/** 挂号*/
// 接诊按钮
$(document).on('click','#jiezhen',function(){
	$('#mymodal-jiezhen').modal();
	showGuaHaoxx();
});

// 接诊弹窗数据
function showGuaHaoxx() {
	var totalNumber = 0;
	var sendData = {
		"rukou": "menzhenrk",
		"xingmingsj": '',
		"zhuangtai": 12,
		"yishengxm": ''
	};
	
	$.ajax({
		url: path + '/guahaoxx/getGuaHaoxxCount',
		type: 'get',
		async: false,
		data: sendData,
		success: function (result) {
			if(result.succsess){
	    		if(result.data > 0) {
	    			totalNumber = result.data;
	    			$('.wushuju').css('display','none');
	        	}else{
	        		$("#guahaoxxtbid").find("tbody").html("");
	        		$('.wushuju').css('display','block').html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
	        	}
	        	if(result.data <= 12) {
	        		$('#pagination-guahaoxx').css('display','none');
	        	}else{
	        		$('#pagination-guahaoxx').css('display','block');
	        	}
	    	}
		}
	});
	
	$('#guahaoxxtbody').html('');
	$('#pagination-guahaoxx').pagination({
		dataSource: path +'/guahaoxx/getGuaHaoxxList?rukou=menzhenrk&zhuangtai='+12+'&yishengxm='+''+'&xingmingsj='+'',
	    locator: 'data',
	    pageSize: 12,
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
	    totalNumber: totalNumber,
	    callback: function(data, pagination) {
			var content = '';
			$.each(data,function(index,v) {
				content += '<tr huanzheid="' + this.huanzheid + '" jiuzhenjlid="'+this.jiuzhenjlid+'"guahaoxxid="' + this.id + '">'
						+'<td width="4%"><span class="cheadbz cheadbz1"></span></td>'
						+ '<td width="6%">' + this.number + '</td>';
						var xbisnull = (this.xingbie == '' || this.xingbie == null);
						var nlisnull = (this.nianling == '' || this.nianling == null);
						if(xbisnull && nlisnull){
							content += '<td width="35%" style="text-align: left;">' + this.huanzhexm +  '</td>';
						}else if(nlisnull){
							content += '<td width="35%" style="text-align: left;">' + this.huanzhexm + ' / ' + this.xingbie + '</td>';
						}else if(xbisnull){
							content += '<td width="35%" style="text-align: left;">' + this.huanzhexm + ' / ' + this.nianling + '</td>';
						}else{
							content += '<td width="35%" style="text-align: left;">' + this.huanzhexm + ' / ' + this.xingbie + ' / ' + this.nianling + '</td>';
						}
						content +='<td width="15%" class="zhuangtai">' + this.zhuangtai + '</td>'
						+ '<td width="15%"><span class="' + (this.guahaoysxm? 'zhiding' : '') + '" title="指定医生"></span>' + this.guahaoysxm + '</td></tr>';
			});
			$('#guahaoxxtbody').html(content);
	    }
	});
}

// 挂号行点击事件
$(document).on('click', '#guahaoxxtbody tr', function () {
	$(this).siblings().find('.cheadbz').removeClass('cheadbz2').addClass('cheadbz1');
	if (!$(this).find('.cheadbz').hasClass('cheadbz2')) {
		$(this).find('.cheadbz').removeClass('cheadbz1').addClass('cheadbz2');
	} else {
		$(this).find('.cheadbz').removeClass('cheadbz2').addClass('cheadbz1');
	}
	if ($(this).find('.zhuangtai').text() == '接诊中' && $(this).find('.cheadbz').hasClass('cheadbz2')) {
		$('#guahaoxx-chexiao').removeAttr('disabled');
	} else {
		$('#guahaoxx-chexiao').attr('disabled', 'disabled');
	}
});

function getHuanzheById(huanzheid) {
	var huanzhexx = '';
	$.ajax({
		type: 'get',
		url: path + '/huanzhe/getHuanZhexxById',
		data: {"id": huanzheid},
		async: false,
		success: function (res) {
			if(res) {
				huanzhexx = res;
			}
		}
	});
	return huanzhexx;
}

// 确定点击事件
$(document).on('click', '#guahaoxx-queding', function () {
	var guahaoxxid = '';
	var ghhuanzheid = '';
	var ghjiuzhenid = '';
	$('#guahaoxxtbody').find('tr').each(function (i,v) {
		if ($(this).find('span').hasClass('cheadbz2')) {
			guahaoxxid = $(this).attr('guahaoxxid');
			ghhuanzheid = $(this).attr('huanzheid');
			ghjiuzhenid = $(this).attr('jiuzhenjlid');
		}
	});
	
	if (guahaoxxid == '') {
		notifyWarning('请先选择接诊患者！');
		return false;
	}
	
	// 填充患者信息
	if (ghhuanzheid != 'null') {
		resetMenZhenxx();
		var huanzhexx = getHuanzheById(ghhuanzheid);
		if (!huanzhexx) return false;
		var strli = '<li id="guahaoli" style="display:none" index="'+huanzhexx.id+','+(huanzhexx.guominshi || '')+','+huanzhexx.nianling+','+huanzhexx.xingming+','+ (huanzhexx.shoujihm || '')+','+huanzhexx.xingbie+','+huanzhexx.nianlingdw+'"></li>';
		$(".xingming").html("");
		$(".xingming").append(strli);
		$(".huanz-message-down").trigger('click');
		$('#guahaoli').trigger('click');
	}
	// 填充历史就诊数据 
	if (ghjiuzhenid != 'null') {
		ignoreInput(ghjiuzhenid, 0, 1);
	}
	$.ajax({
		url: path + '/guahaoxx/updateZhuangtaiById',
		type: 'post',
		async: false,
		data: {
			"id": guahaoxxid,
			"zhuangtai": 2
		},
		success: function (data) {
			if (data.data == MSG_SUCCESS) {
				notifySuccess('接诊成功');
				$('#higuahaoid').val(guahaoxxid);
				$('#mymodal-jiezhen').modal('hide');
			} else {
				notifyWarning('接诊失败!');
			}
		}
	});
	
});

// 撤销点击事件
$(document).on('click', '#guahaoxx-chexiao', function () {
	if ($(this).attr('disabled') == 'disabled') return false;
    var guahaoxxid = '';
    $('#guahaoxxtbody').find('tr').each(function (i, v) {
        if ($(this).find('span').hasClass('cheadbz2')) {
            guahaoxxid = $(this).attr('guahaoxxid');
        }
    });
    if (guahaoxxid == '') return false;
    $.ajax({
        url: path + '/guahaoxx/revokeGuaHao',
        type: 'post',
        async: false,
        data: {
            "guahaoxxid": guahaoxxid,
        },
        success: function (data) {
            if (data.data == MSG_SUCCESS) {
            	showGuaHaoxx();
                notifySuccess('撤销成功');
            } else {
                notifyWarning('撤销失败!');
            }
        }
    });    
});
/** 挂号结束*/

// Let's Rock!
$(document).on('click','#jiezhen',function(){
	$('#mymodal-jiezhen').modal()
})
var keyArry = [];
$(function() {
    /**正则判断字符数*/
    function getByteLen(val) {
        var len = 0;
        for ( var i = 0; i < val.length; i++) {
            var a = val.charAt(i);
            if (a.match(/[^\x00-\xff]/ig) != null) {
                len += 2;
            } else {
                len += 1;
            }
        }
        return len;
    }
    
    //数量单位可输入
    $(document).on("blur", "[name='dancijldw']", function() {
        var danwei = $(this).val();
        if (getByteLen(danwei) > 4) {
            notifyWarning('请输入1-2个字符');
            this.focus();
            $(this).addClass("n-invalid");
            return false;
        } else {
            $(this).removeClass("n-invalid");
        }
    });
    
    // 医保信息未显示时智能诊断位置
    if($('.cYiBaoInfoNav').css('display') == 'none'){
    	$('.cgmz-znzd-nav').css('top','80px');
    }
    
    //数量单位适量输入改变单剂量是否可输入
    $(document).on("input","[name='dancijldw']",function() {
        if ($(this).val() != "适量") {
            $(this).parent().find("[name='dancijl']").removeAttr('readOnly');
        } else {
            $(this).parent().find("[name='dancijl']").attr('readOnly','readOnly');
        }
    });

    //数量单位可输入
    $(document).on("blur", "[name='kaiyaodw']", function() {
        var kaiyaodw = $(this).val();
        if (getByteLen(kaiyaodw) > 4) {
            notifyWarning('包装规格请输入1-2个字符');
            this.focus();
            $(this).addClass("n-invalid");
            return false;
        } else {
            $(this).removeClass("n-invalid");
        }
    });
    
    //数量单位可输入
    $(document).on("blur", "[name='danwei']", function() {
        var danwei = $(this).val();
        if (getByteLen(danwei) > 4) {
            notifyWarning('包装规格请输入1-2个字符');
            this.focus();
            $(this).addClass("n-invalid");
            return false;
        } else {
            $(this).removeClass("n-invalid");
        }
    });
    
 // 精确查找商品
	//药品
$(document).on('click','#jingqueczspyp',function(){
	var mingcchen = $(this).parent().parent().find(".yaopinmc").val();
	$(this).parent().parent().find(".yaopinmc").val('').addClass('qiaojie');
	$(this).parent().parent().parent().find(".g-wmfinp-warning").css('display','none');
	$(this).parent().parent().parent().find(".g-wmfinp-danger").css('display','none');
	if($(this).parents('.western-medicine').css('display') == 'block'){
		$(this).parent().parent().parent().find(".cgmdc-input3").val('');
		$(this).parent().parent().parent().find(".cgmdc-input4").val('');
		$(this).parent().parent().parent().find(".cgmdc-input51").val('');
		$(this).parent().parent().parent().find(".cgmdc-input52").val('');
		$(this).parent().parent().parent().find(".cgmdc-input61").val('');
		$(this).parent().parent().parent().find(".cgmdc-input62").val('').attr('readonly',false);
		$(this).parent().parent().parent().find(".cgmdc-input7").val('').attr('readonly',false);
		$('.check').removeClass("check2").addClass("check1");
		$('#checkHaocai').parent().parent('.modal-seh-leixing').css('display','block');
		$('.chazhc').css('display','none');
		$('.chazcy').css('display','none');
	}else{
		$(this).parent().parent().parent().find("[name='danjiliang']").val('');
		$(this).parent().parent().parent().find("[name='danwei']").val('').attr('readonly',false);
		$(this).parent().parent().parent().find("[name='beizhu']").val('');
		$(this).parent().parent().parent().find("[name='jine']").val('').attr('readonly',false);
		$('.check').removeClass("check2").addClass("check1");
		$('.chazhc').css('display','none');
		$('#checkYinpian').removeClass("check1").addClass("check2");
		$('#checkHaocai').parent().parent('.modal-seh-leixing').css('display','none');
	}
	$(this).parent('ul').html('').css('display','none');
	$("#shangpinjqcz").modal();
	$('#shangpinmc').val(mingcchen);
	$('#shengchancj').val('');
	$('#gongyings').val('');
	$('#checkHaocai').removeClass("check2").addClass("check1");
	showJingq();
});
	//耗材
$(document).on('click','#jingqueczsp',function(){
	var mingcchen = $(this).parent().parent().find("#haocaiName").val();
	$(this).parent().parent().find("#haocaiName").val('').addClass('qiaojie');
	$(this).parent().parent().parent().find(".g-wmfinp-warning").css('display','none');
	$(this).parent().parent().parent().find(".g-wmfinp-danger").css('display','none');
	$(this).parent().parent().parent().find("[name='shuliang']").val('');
	$(this).parent().parent().parent().find("[name='danwei']").val('').attr('readonly',false).css('background','#fff');
	$(this).parent().parent().parent().find("[name='jine']").val('').attr('readonly',false);
	$('.check').removeClass("check2").addClass("check1");
	$('#checkHaocai').removeClass("check1").addClass("check2");
	$('#checkHaocai').parent().parent('.modal-seh-leixing').css('display','none');
	$('.chazhc').css('display','none');
	$(this).parent('ul').html('').css('display','none');
	$("#shangpinjqcz").modal();
	$('#shengchancj').val('');
	$('#gongyings').val('');
	$('#shangpinmc').val(mingcchen);
	showJingq();
});

    //智能诊断选择
    $(document).on("click", '.pzhizhengzd', function() {
        var add = $(this).children("span.left");
        if (add.hasClass("changjzd-bottom")) {
            add.removeClass("changjzd-bottom").addClass("changjzd-top");
        } else {
            add.removeClass("changjzd-top").addClass("changjzd-bottom");
        }
    });
    //input中focus添加蓝色边框
    $(".dongt-border").focusin(function() {
        $(".dongt-border").removeClass("input-border");
        $("input").removeClass("input-border");
        $(this).addClass("input-border");
    });
    $(".dongt-border").blur(function() {
        $(".dongt-border").removeClass("input-border");
        $(this).removeClass("input-border");
    });
    //常规门诊导航标识
    $("#changguimz").css( {
        "border-bottom" : "4px solid #097c25",
        "height" : "60px"
    });
    $("#changguimz").siblings().css( {
        "border" : "0"
    });
    //诊断控制输入128个字
    $("#input-diagnosis").keyup(function() {
        if ($(this).val().length > 128) {
            notifyWarning("诊断最大可填写128个字");
            var text = $(this).val().substring(0, 128);
            $(this).val(text);
        }
    });
    /*患者信息折叠*/
    $(".huanz-message-up").click(function() {
        $(".zhedie").hide();
        $(".huanz-message-down").css("display", "block");
    });
    $(".huanz-message-down").click(function() {
        $(".zhedie").show();
        $(this).css("display", "none");
    });
    //如果诊疗跳转过来的改变光标定位
    if (huanzZhenliao) {
        $("#first-info").focus();
    } else {
        $("#inputname").focus();
    }
    //popover
    $(document).on("mouseover", ".g-mz-delete", function() {
        $(this).popover('show');
    });
    $(document).on("mouseout", ".g-mz-delete", function() {
        $(this).popover('hide');
    });
    $(document).on("mouseover", ".g-wmfinp-warning", function() {
        $(this).popover('show');
    });
    $(document).on("mouseout", ".g-wmfinp-warning", function() {
        $(this).popover('hide');
    });
    $(document).on("mouseover", ".g-wmfinp-danger", function() {
        $(this).popover('show');
    });
    $(document).on("mouseout", ".g-wmfinp-danger", function() {
        $(this).popover('hide');
    });
    $(document).on("mouseover", ".cgmdc-input3", function() {
        $(this).popover('show');
    });
    $(document).on("mouseout", ".cgmdc-input3", function() {
        $(this).popover('hide');
    });
    $(".g-1lm-icon").hover(function() {
        $(this).popover('show');
    }, function() {
        $(this).popover('hide');
    });
    $(".cgmdc-input3").hover(function() {
        $(this).popover('show');
    }, function() {
        $(this).popover('hide');
    });
    //药品点击第一行取消enter事件
    $(document).on("focus", ".yaopinmc", function() {
        // enterToTab = false;
    });
    //2.0智能诊断
    $(".ckbs-main-content .txt-title").click(function() {
        $(this).siblings(".txt-content").toggle();
    });
    //TODO
    $(".ckbs-close").click(function() {
        $(".ckbs-box").css("display", "none");
    });

    //详细记录点击事件
    $('.jzjl-xqjl-nav').click(function() {
        $('.sd-right').toggle();
    });
    //今日门诊点击事件
    $('.wzl-jrmz-nav').click(function() {
        if ($(this).hasClass("wzl-jrmz-navadd")) {
            return false;
        } else {
            $(".routine-diagnosis").hide();
            $('#yibao-ybinfo').hide();
            $('.r-side').toggle();
        }
    });
    
    /* -----图片上传部分  start--------- */
     // keyArray var在定义在顶层
	 // 打开上传入口
	 $("#img-rukou").click(function(){
		 console.log(1)
	 	// 获取二维码
	 	$.post(path + "/handelImg/createQrcode",{},function(result){
	 		if(result.succsess){
	 			
	 			$('#cfmk-img-wechat img').attr("src",result.data.qrcodeStr);
	 			keyArry.push(result.data.key);
	 			console.log(keyArry)
	 			//$(".img-hasimginof #key").attr("value",result.data.key);
	 			$('#cfmk-img-wechat').modal();
	 		}else{
	 			notifyWarning(result.errorInfo);
	 		}
	 	});
	 });
	
	 $("#img-wechat-confirm").click(function(){
	 	$("#cfmk-img-wechat").modal('hide');
	 	getTuxiangzl(keyArry, null, ".img-hasimginof", 1);
	 	nav_slide('.cgmz-dw-original');
	 });
	 $("#shuaxin").click(function(){
	 	getTuxiangzl(keyArry, null, ".img-hasimginof", 1);
	 });

 /* -----图片上传部分  end--------- */
    //智能诊断点击事件
    $('.cgmz-znzd-nav').click(function() {
        $(".r-side").hide();
        $('#yibao-ybinfo').hide();
        var thisHeight =parseInt($(this).css('top'));
        $('.routine-diagnosis').css('top',thisHeight-24+'px');
        $('.routine-diagnosis').toggle();
    });
    //智能诊断点击事件
    $('.cYiBaoInfoNav').click(function() {
        $(".r-side").hide();
        $(".routine-diagnosis").hide();
        $('#yibao-ybinfo').toggle();
        var hello = $('.cYiBaoInfoNav').find('img');
        // start-小灯泡效果
        if(hello.length<1){
        var img ='<img src="'+path+'/image/changgmz/cgmz-light.gif"/>';
		$('.cYiBaoInfoNav').css({'background':'#1ebdff','border-color':'#1ebdff',});
		$('.cgmz-znzd-nav').css('top','200px');
				$('.cYiBaoInfoNav').prepend(img);
				
		}else{
			//恢复原样
			$('.cYiBaoInfoNav').css({'background':'#009943','border-color':'#009943'});
			$('.cgmz-znzd-nav').css('top','160px');
			$('.cYiBaoInfoNav img').remove();
		}
      // end-小灯泡效果
    });
    //开药单位点击事件
    $(document).on(
            "click",
            ".kaiyaodw li",
            function() {
                var bText = $(this).text();
                $(this).parent().siblings(".dropdown-toggle").val(bText);
                $(this).parent(".dropdown-menu").css("display", "none");
                $(this).parent().parent().parent().parent().find("input:visible:not('.wm-group,[name=\"beizhu\"]')")
                        .each(function() {
                            if ($(this).val() == "") {
                                $(this).focus();
                                return false;
                            }
                            ;
                        });
            });
    //寄存天数点击
    $(document).on(
            "click",
            ".cgmz-jcts li",
            function() {
                var bText = $(this).text();
                $(this).parent().siblings(".dropdown-toggle").val(bText);
                $(this).parent(".dropdown-menu").css("display", "none");
                $(this).parent().parent().parent().parent().find("input:visible:not('.wm-group')").each(function() {
                    if ($(this).val() == "") {
                        $(this).focus();
                        return false;
                    }
                });
            });
    $(document).on(
            "click",
            "#leixing2 li",
            function() {
                var bText = $(this).text();
                $(this).parent().siblings("#f-le-fenlei2").text(bText).removeClass("n-invalid");
                $(this).parent(".dropdown-menu").css("display", "none");
            });
    $(document).on("click",
            "#cghc-fydw-ul li",
            function() {
                var bText = $(this).text();
                //$(this).parent().siblings(".dropdown-toggle").text(bText);
            $(this).parent().siblings(".dropdown-toggle").val(bText).removeClass("n-invalid");
            $(this).parent(".dropdown-menu").css("display", "none");
            $(this).parent().parent().parent().parent().find("input:visible")
                    .each(function() {
                        if ($(this).val() == "") {
                            $(this).focus();
                            return false;
                        }
                    });
        });
    $(document).on(
            "click",
            "#leixing li",
            function() {
                var bText = $(this).text();
                $(this).parent().siblings("#f-le-nianlingdw").text(bText).removeClass("n-invalid");
                $(this).parent().siblings("#hinianlingdw").val(bText);
                $(this).parent(".dropdown-menu").css("display", "none");
            });

    //控制性别点击样式
    $(document).on("click", ".radio-label", function() {
        $(this).addClass("on").siblings().removeClass("on");
    });
    $(document).on("click", ".cgmz-td-label", function() {
        $(this).addClass("on").siblings().removeClass("on");
    });
    //诊断内容删除事件
    $(document).on('click', '.cgmz-l2zd-dropimg', function() {
        $(this).parent().remove();
    });
    //常用医嘱checkbox事件
    $(document).on("click", ".cymb-check1", function() {
        if ($(this).hasClass("cymb-check2")) {
            $(this).removeClass("cymb-check2").addClass("oncymb-check1");
        } else {
            $(this).addClass("cymb-check2").removeClass("oncymb-check1");
        }
        $(this).parent().toggleClass("radio-selected");
    });
    //是否寄存点击事件
    $(".c-check1").on("click", function() {
        $(".cgmz-check-toggle").toggle();
        var zhuangTai = $(".cgmz-check-toggle").css("display");
        if (zhuangTai != 'inline') {
            $(".cgmz-check-toggle #jicunts").val('');
        }
        if ($(this).hasClass("c-check2")) {
            $(this).removeClass("c-check2").addClass("on-check1");
            $('#hijicunbz').val(0);
        } else {
            $(this).addClass("c-check2").removeClass("on-check1");
            $('#hijicunbz').val(1);
        }
    });
});
$(document).on("click", "*", function() {
    $(".r-side").css('display', 'none');
    $(".routine-diagnosis").css('display', 'none');
    $('#yibao-ybinfo').css('display', 'none');
});
$(".wzl-jrmz-nav").click(function() {
    return false;
});
$(".cgmz-znzd-nav").click(function() {
    return false;
});
$(".cYiBaoInfoNav").click(function() {
    return false;
});
//智能诊断按钮变换
$(document).on("mouseover", ".routine-diagnosis", function() {
    $(this).addClass("hello");
});
$(document).on("mouseout", ".routine-diagnosis", function() {
    $(this).removeClass("hello");
});
$(document).on("click", ".routine-diagnosis", function() {
    if ($(".routine-diagnosis").hasClass("hello")) {
        $(this).css("display", "block");
    } else {
        $(this).css("display", "none");
    }
    return false;
});


// 智能诊断按钮变换
$(document).on("click", ".c-check0", function() {
    if ($(this).hasClass("c-check2")) {
        $(this).removeClass("c-check2").addClass("on-check1");
    } else {
        $(this).addClass("c-check2").removeClass("on-check1");
    }
});

$(document).on('blur', '.hzn-name-input4', function() {
    var hello = $(this).val();
    hello = getFloatStr(hello);
    $(this).val(hello);
});

$(document).on('blur', '.input-jine', function() {
    var hello = $(this).val();
    hello = getFloatStr(hello);
    $(this).val(hello);
});

//添加成药
function getCWVal(obj) {
    var flag = false;
    if (!obj.html()) {
        flag = true;
    } else {
        obj.find("input:text:not('#tieshu'):not('#input-body-weight')").each(
                function() {
                    var finded = $(this).val();
                    if (finded != "") {
                        flag = true;
                    }
                });
    }
    return flag;
}
$(document).on("click", ".add-western", function() {
    var len = $(".western-medicine").length;
    if (getCWVal($(".western-medicine:last"))) {
        $(".western-medicine:last").after(shengchengchengycf(len));//添加成药模板
    }
    $(".western-medicine:last .yaopinmc:first").focus();
    $(".western-medicine:last").addClass("animate-drug");
});
/*成药每次剂量为适量时，数量不可编辑*/
$(document)
        .on("click",".dancijldw li",function() {
                    var shuliang = $(this).parent().parent().find('[name="kaiyaoliang"]').val() 
                    		|| $(this).parent().parent().find('[name="danjiliang"]').val();
                    var danjia = $(this).parent().parent().parent().find('[name="danjia"]').val();
                    var kaiyaodwul = $(this).parent();
                    var kaiyaodwli = kaiyaodwul.find('li');
                    var baozhuangdw = $(this).parent().parent().parent().find('[name="baozhuangdw"]').val();
                    var chailingsl = $(this).parent().parent().parent().find('[name="chailingsl"]').val();
                    var kucunsl = $(this).parent().parent().parent().find('[name="kucunsl"]').val();
                    var bText = $(this).text();
                    $(this).parent().siblings(".dropdown-toggle").val(bText).removeClass("n-invalid");
                    $(this).parent(".dropdown-menu").css("display", "none");
                    var _text = $(this).parent().prev(".cgmdc-input52").val();
                    if (_text == "适量") {
                        $(this).parent().prev().prev(".cgmdc-input51").attr('readOnly', true).val('').removeClass("n-invalid");
                        $(this).parent().parent().parent().parent().find("input:visible:not(.wm-group,.cgmdc-input51,[name=\"beizhu\"])")
                                .each(function() {
                                    if ($(this).val() == "") {
                                        $(this).focus();
                                        return false;
                                    }
                                });
                    } else {
                        $(this).parent().prev().prev(".cgmdc-input51").attr('readOnly', false);
                        $(this).parent().parent().parent().parent().find("input:visible:not('.wm-group,[name=\"beizhu\"]')")
                                .each(function() {
                                    if ($(this).val() == "") {
                                        $(this).focus();
                                        return false;
                                    }
                                });
                    }
                    if (danjia != "" && danjia != "null" && danjia != 0
                            && isZhengzs(shuliang)) {//当有单价时才计算
                        if (shuliang != "") {
                            if (kaiyaodwli.length == 2 && bText == baozhuangdw) {//支持拆零且选择的是包装单位
                                danjia = multiply(danjia, chailingsl);
                                var zongshuliang = multiply(shuliang, chailingsl);
                                if (Number(kucunsl) < Number(zongshuliang)) {//库存不足提示
                                    var danger = $(this).parent().parent().parent().find('.g-wmfinp-danger').css("display");
                                    if (danger == 'block') {
                                        $(this).parent().parent().parent().find('.g-wmfinp-warning').css('right', '35px');
                                    } else {
                                        $(this).parent().parent().parent().find('.g-wmfinp-warning').css('right', '12px');
                                    }
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','block');
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').attr('data-content', '该药材库存不足');
                                } else {
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','none');
                                }
                            } else {
                                if (Number(kucunsl) < Number(shuliang)) {//库存不足提示
                                    var danger = $(this).parent().parent().parent().find('.g-wmfinp-danger').css("display");
                                    if (danger == 'block') {
                                        $(this).parent().parent().parent().find('.g-wmfinp-warning').css('right', '35px');
                                    } else {
                                        $(this).parent().parent().parent().find('.g-wmfinp-warning').css('right', '12px');
                                    }
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','block');
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').attr('data-content', '该药材库存不足');
                                } else {
                                    $(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','none');
                                }
                            }
                            var jine = multiply(shuliang, danjia);
                            $(this).parent().parent().parent().find(
                                    '[name="jine"]').val(parseFloat(roundUtil(jine, 8)));
                        } else {
                            $(this).parent().parent().parent().find(
                                    '[name="jine"]').val(0.00);
                        }
                    }
                });

//添加草药
$(document).on("click", ".add-chinese", function() {
    var len = $(".chinese-medicine").length;
    if (getCWVal($(".chinese-medicine:last"))) {
        $(".chinese-medicine:last").after(shengchengcaoycf(len));//添加成药模板
    }
    $(".chinese-medicine:last #tieshu").focus();
    $(".chinese-medicine:last").addClass("animate-drug");
    $(".chinese-medicine:last").find('[name="jixing"]').val('饮片');
});
//删除成、草药	
$(document).on("click",".medicine-delete", function() {
                    var finded = "";
                    var parent12 = $(this).parent().parent();
                    parent12.find("input:text:not('#tieshu'):not('#input-body-weight')").each(function() {
                    	finded += $(this).val();
                            });
                    if (finded != "") {
                        $("#cgmz-cccf-info").modal();
                        parent12.addClass("cfcc-yorn");
                    } else {
                        parent12.remove();
                    }
                    var $this = $('.western-medicine');
                    $this.find('.chinese-head').each(
                    	function(i, e) {
                    		$(e).html('成药处方' + (i + 1) + '<span class="medicine-delete">删除处方</span>');
                                    });
                    var $that = $('.chinese-medicine');
                    $that.find('.chinese-head').each(function(i, e) 
                    	{
                        $(e).html('草药处方' + (i + 1) + '<span class="medicine-delete">删除处方</span>');
                        });
                });
			$("#cgmz-cccf-queding").click(function() {
                    $(".cfcc-yorn").remove();
                    var $this = $('.western-medicine');
                    $this.find('.chinese-head').each(function(i, e) {
                        $(e).html('成药处方' + (i + 1) + '<span class="medicine-delete">删除处方</span>');
                        });
                    var $that = $('.chinese-medicine');
                    $that.find('.chinese-head').each(function(i, e) {
                    	$(e).html('草药处方' + (i + 1) + '<span class="medicine-delete">删除处方</span>');
                                    });
                    $("#cgmz-cccf-info").modal('hide');
                    $("#sphejije").trigger("click");
                });
//成药药品添加一行
$(document).off("focusout", '.western-medicine tbody tr .wm-medicine-name');
$(document).on('focusout', '.western-medicine tbody tr .wm-medicine-name',function() {
	if(yanhouzhsj){
		var $parents = $(this).parent().parent().parent('tbody');
	    var $parent = $parents.children("tr");
	    var len = $parent.length;
	    var isLast = $parents.find(".wm-medicine-name").last().is($(this));
	    if (isLast && $(this).val() != "") {
	    	console.log(isLast);
	    	console.log($(this).val());
	        $(this).parent().parent('tr').after(shengchengchengyyh(len));
	    }
	    yanhouzhsj = false;
	}
});
//在草药表格后面添加一行
$(document).off("focusout", '.chinese-medicine tbody tr .wm-medicine-name');
$(document).on('focusout', '.chinese-medicine tbody tr .wm-medicine-name',function() {
	if(yanhouzhsj){
	    danjijine($(this));
	    var $parents = $(this).parent().parent().parent('tbody');
	    var $parent = $parents.children("tr");
	    var len = $parent.length;
	    var isLast = $parents.find(".wm-medicine-name").last().is($(this));
	    if (isLast && $(this).val() != "") {
	        $(this).parent().parent('tr').after(shengchengcaoyyh(len));
	    }
	    yanhouzhsj = false;
	}	
	    return false;
});
//移除草药行事件
$(document).on("click", ".pointer3", function() {
    var $shanchuTbody = $(this).parent().parent().parent().parent();
    removeCaoyaoHang(this);
    $(this).parent().siblings(".hzn-name-td2").find(".dropdown-menu").text('');
    xuanzeypFlagbf = false;
    danjijine($shanchuTbody);
    weishutongji($shanchuTbody);
    jisuanYmje();
});
//移除成药行事件
$(document).on('click', '.pointer2', function() {
    removeChengyaoHang(this);
    $(this).parent().siblings(".hzn-name-td2").find(".dropdown-menu").text('');
    xuanzeypFlagbf = false;
    jisuanYmje();
});

//第一行中草药清空事件
$(document).on('click', '.pointer-cc1', function() {
    var $this = $(this);
    var $parent = $this.parent().parent();
    $parent.find("input:text").val("").removeClass("n-invalid");
    $parent.find(".g-wmfinp-warning").css("display", "none");
    $parent.find(".g-wmfinp-danger").css("display", "none");
});

//添加耗材费用
$(document).off("click", '.cgmz-l3-group .g-l-1right .wzl-l3-header1');
$(document)
        .on('click','.cgmz-l3-group .g-l-1right .wzl-l3-header1',function() {
                    var $parents = $('.cgmz-l3-group1').find('tbody');
                    var $parent = $parents.children("tr");
                    var len = $parent.length;
                    var clone = '<tr class="medicine-item-tr">'
                            + '<td class="hzn-name-td2 dropdown-search-li">'
                            + '<input type="text" class=" form-control dropdown-toggle hzn-name-input2 dropdowninput" id="haocaiName" autocomplete="off" data-rule="耗材名称:length(1~128)"  data-target="#msg_holder" name="mingcheng" onblur="jiancehc(this)"><div class="g-wmfinp-warning" style="top:13px;right:17px;" data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'
                            + '<ul class="dropdown-menu li-width f-input-li haocai"  style="top: 36px; width: 159%; left:0; display: none;" role="menu">'
                            + '</ul>'
                            + '<input type="hidden" name="danjia" >'
                            + '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="1">'
                            + '<input type="hidden" name="pingtaihcid" >'
                            + '<input type="hidden" name="zhensuohcid" >'
                            + '<input type="hidden" name="shengchancj" >'
                            + '<input type="hidden" name="baozhuanggg" >'
                            + '<input type="hidden" name="gongyingshang" >'
                            + '<input type="hidden" name="ptuuid" >'
                            + '</td>'
                            + '<td class="hzn-name hzn-name-td3 dropdown-search-li"><input type="text" placeholder="数量" autocomplete="off" class=" form-control hzn-name-input3 dropdowninput shuliang" data-target="#msg_holder" name="shuliang" onkeyup="jisuanhcje(this)"> '
                            + '<input type="text" placeholder="单位" name="danwei" class="form-control hzn-name-input32 dropdown-toggle" id="cghc-fydw" style="width:70px;">'
                            + '<ul class="dropdown-menu li-width hcdanwei" id="cghc-fydw-ul" role="menu">'
                            + '<li>盒</li>'
                            + '<li>瓶</li>'
                            + '<li>支</li>'
                            + '<li>袋</li>'
                            + '<li>丸</li>'
                            + '<li>片</li>'
                            + '</ul>'
                            + '</td>'
                            + '<td class="hzn-name-td4">'
                            + '<span class="cgl3-td-number">金额</span><input type="text" autocomplete="off" class=" form-control hzn-name-input4 jine inp-select" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" value="0.00">  元'
                            + '<input type="hidden" name="chailingsl">'
                            + '<input type="hidden" name="baozhuangdw">'
                            + '<input type="hidden" name="kucunsl">'
                            + '</td>'
                            + '<td style="text-align: left;"><div class="g-mz-delete pointer31" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'
                            + path + '../static/image/shanc.png" alt=""></div></td>'
                            + '</tr>';

                    $('.cgmz-l3-group1 tbody tr:last').after(clone);
                    $(".cgmz-l3-group1 tbody tr:last .hzn-name-input2").focus();

                });
//添加检查治疗项
$(document).off("click", '.cgmz-l3-group .g-l-1right .wzl-l3-header3');
$(document).on('click','.cgmz-l3-group .g-l-1right .wzl-l3-header3',function() {
                    var $parents = $(this).parent().parent().parent('tbody');
                    var $parent = $parents.children("tr");
                    var len = $parent.length;
                    var clone = '<tr class="medicine-item-tr">'
                            + '<td class="hzn-name-td2 dropdown-search-li">'
                            + '<input type="text" class=" form-control hzn-name-input2 dropdowninput dropdown-toggle" id="jianchaName" autocomplete="off"  name="mingcheng"><ul class="dropdown-menu li-width f-input-li jianchax"   style="top: 36px; width: 99%;left:0; display: none;" role="menu"></ul>'
                            + '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'
                            + (len + 1)
                            + '">'
                            + '<input type="hidden" name="pingtaijcxid" id="hipingtaijcxid"><input type="hidden" name="zhensuojcxid" id="hizhensuojcxid">'
                            + '</td>'
                            + '<td class="hzn-name-td4">'
                            + '<span class="cgl3-td-number">金额</span><input type="text" class=" form-control hzn-name-input4 jine inp-select" data-target="#msg_holder" autocomplete="off" name="jine" value="0.00"> 元</td>'
                            + '<td style="text-align: left;"><div class="g-mz-delete pointer33" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'
                            + path + '../static/image/shanc.png" alt=""></div></td>'
                            + '</tr>';
                    $('.cgmz-l3-table3 tbody tr:last').after(clone);
                    $(".cgmz-l3-table3 tbody tr:last .hzn-name-input2").focus();
                });
//上面三者的删除行事件，依次
$(document).on('click','.pointer31',function() {
            var $this = $(this);
            var $parent = $this.parent();
            var $tr = $parent.parent().parent();
            var length = $(".cgmz-l3-table1 tbody tr").length;
            $(this).parent().siblings(".hzn-name-td2").find(".dropdown-menu")
                    .text('');
            if (length <= 1) {
                $this.parent().parent().find("input:text").removeAttr(
                        'readOnly');
                $this.parent().parent().find("input:text").val("").removeClass(
                        "n-invalid");
                $this.parent().parent().find('[name="danwei"]').css(
                        'background-color', '#fff');

                $this.parent().parent().find(".g-wmfinp-warning").css(
                        "display", "none");
                $this.parent().parent().find(".g-wmfinp-danger").css("display",
                        "none");
            } else {
                $(this).popover('hide');
                $(this).parent().parent().remove();

                $tr.find(".wm-paixu").each(function(i, e) {
                    $(e).val(+(i + 1));
                });
            }
            xuanzeypFlagbf = false;
            jisuanYmje();
        });
$(document).on('click','.pointer33',function() {
            var $this = $(this);
            var $parent = $this.parent();
            var $tr = $parent.parent().parent();
            var length = $(".cgmz-l3-table3 tbody tr").length;
            $(this).parent().siblings(".hzn-name-td2").find(".dropdown-menu")
                    .text('');
            if (length <= 1) {
                $this.parent().parent().find("input:text").removeAttr(
                        'readOnly');
                $this.parent().parent().find("input:text").val("").removeClass(
                        "n-invalid");
                $this.parent().parent().find(".g-wmfinp-warning").css(
                        "display", "none");
                $this.parent().parent().find(".g-wmfinp-danger").css("display",
                        "none");
            } else {
                $(this).popover('hide');
                $(this).parent().parent().remove();
                $tr.find(".wm-paixu").each(function(i, e) {
                    $(e).val(+(i + 1));
                });
            }
            xuanzeypFlagbf = false;
            jisuanYmje();
        });

$(".xiangxiandls").css('display', 'none');
$('.weizl-fd1-1').css('margin-left', "0");
//点击患者li
var huanzheid = null;
$(document).on("click", ".xingming li", function() {
    var bText = $(this).text();
    var bValue = $(this).attr("index");
    var str = bValue.split(",");
    huanzheid = str[0];
    var jiuzhenhzid = str[0];
    $('#inputname').val(str[3]);
    $('#inputname').attr('readOnly', 'true');
    if (str[2] != 'null') {
        $('#inputage').val(str[2]);
    }

    $('#inputphone').val(str[4]);
    $('#g-allergy').val(str[1]);
    $('#div-allergy').html(str[1]);

	if(str[5]== 1) {
		$('#work-label').trigger('click');
	}else if(str[5]==2){
		$('#stop-label').trigger('click');
	}

    if (str[6] == '岁') {
        $("#f-le-nianlingdw").text('岁');
    } else {
        $("#f-le-nianlingdw").text('月');
    }
    $(this).parent().html("");
    $('#isNew').val(0);
    $('#huanzheid').val(str[0]);
    $(".f-input-li").css("display", "none");
    $('#hz_serch').val("");
    $("#mymodal-lsjz").modal('hide');
    $(".g-l-1right").css('display', 'block');
	if (getLiShijzcs(jiuzhenhzid) != 0) {
		$('.g-l-1r-bottom').css('display','inline-block');
	} else {
		$('.g-l-1r-bottom').css('display','none');
	}
    $('.g-1lm-icon ').css("display", "block");
});
// 获取该患者就诊次数
function getLiShijzcs(jiuzhenhzid) {
	var totalNumber = 0;
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url: path + "/huanzhe/getHuanzhejzjlCount",
	    //传送数据
	    data:{id: jiuzhenhzid},
	    async: false,
	    //请求成功完成后要执行的方法
	    success: function(data){
	    	totalNumber = data;
	    }
	});
	return totalNumber;
}
//删除患者
$('#deleteHuanzhe').click(function() {
    huanzheid = null;
    jiuzhenjlid2 = null;
    $('#inputname').val('');
    $('#inputname').removeAttr('readOnly');
    $('#inputage').val('');

    $('#inputphone').val('');
    $("#inputphone").removeClass("n-invalid");
    $('#g-allergy').val('');
    $("#div-allergy").text('');

    $('#nan').removeAttr('checked');
    $('#nv').removeAttr('checked');
    $('#work-label').attr('class', 'radio-label cgbj-input');
    $('#stop-label').attr('class', 'radio-label');

    $("#f-le-nianlingdw").text('岁');

    $('#isNew').val(1);
    $('#huanzheid').val('');
    $(".xiangxiandls").css('display', 'none');
    $('.weizl-fd1-1').css('margin-left', "0");
    $('.g-1lm-icon ').css("display", "none");
});
var qx_shoukuan = false;//收费权限
var canbaoryid = 0;
//从患者信息诊疗按钮跳转过来
function getChangGuimzcs(id, shoukuan) {
    qx_shoukuan = shoukuan;
    $.ajax( {
        type : "get",
        //获取json文件路径
        url : "./huanzhe/getHuanzheById",
        //传送数据
        data : {
            id : id
        },
        //请求成功完成后要执行的方法
        async : false,
        success : function(data) {
        	console.log(data)
            //显示详情信息
        if (data != "") {
            canbaoryid = data.huanzhexx.canbaoryid;
            $('#inputname').val(data.huanzhexx.xingming);
            $('#inputname').attr('readOnly', 'true');
            $('#inputage').val(data.huanzhexx.nianling);
            $('#inputphone').val(data.huanzhexx.shoujihm);
            $('#g-allergy').val(data.huanzhexx.guominshi);
            $('#div-allergy').html(common_util.nullToEmpty(data.huanzhexx.guominshi));

            if (data.huanzhexx.xingbie == 1) {
                $('#nan').attr('checked', 'checked');
                $('#work-label').attr('class', 'radio-label cgbj-input on');
                $('#stop-label').attr('class', 'radio-label');
            } else if (data.huanzhexx.xingbie == 2) {
                $('#nv').attr('checked', 'checked');
                $('#stop-label').attr('class', 'radio-label on');
                $('#work-label').attr('class', 'radio-label cgbj-input');
            }

            if (data.huanzhexx.nianlingdw == '岁') {
                $("#f-le-nianlingdw").text('岁');
            } else {
                $("#f-le-nianlingdw").text('月');
            }

            $('#isNew').val(0);
            $('#huanzheid').val(data.huanzhexx.id);
            huanzheid = data.huanzhexx.id;
            $("#deleteHuanzhe").css("display", "block");
            $(".xiangxiandls").css("display", "block");
			if (getLiShijzcs(huanzheid) != 0) {
				$('.g-l-1r-bottom').css('display','inline-block');
			} else {
				$('.g-l-1r-bottom').css('display','none');
			}
    }

}
    });
    //获取医保信息
	$.ajax({
			type : "post",
			url : path + "/yibao/getYbRenyuancbjbxxById",
			data : {"id": canbaoryid},
			async : false,
			success : function(data){
				console.log(111)
				console.log(data)
				$('#shengfenzh').text(data.shenfenzh);
				$('#renyuanlb').text(data.renyuanlb);
				$('#yibaokh').text(data.yibaokh); 
				$('#binglibh').text(data.yiliaozh); 
				$('#bennianzhye').text(data.dangnianzhye);
				$('#linianzhye').text(data.linianzhye);
				$('#higerenbh').val(data.gerenbh);
			},
		});
	}
	
	//点击检查项li
	$(document).on("click",".jianchax li",function(){
		var bText = $(this).text();
		var str = $(this).attr('index').split(',');
		
		var flag;
		$(this).parent().parent().parent().addClass('notComprareThis');//给当前行加上一个标记
		$(this).parent().parent().parent().parent().find('[name="zhensuojcxid"]').each(function(){
			if(!$(this).parent().parent().hasClass('notComprareThis')) {//当前行不比较
				if(str[2]==1&&str[1]==$(this).val()){
					notifyWarning('请不要添加重复诊疗项');
					flag = true;
					return false;
				}
			}
		});
		$(this).parent().parent().parent().parent().find('[name="pingtaijcxid"]').each(function(){
			if(!$(this).parent().parent().hasClass('notComprareThis')) {
				if(str[2]==0&&str[1]==$(this).val()){
					notifyWarning('请不要添加重复诊疗项');
					flag = true;
					return false;
				}
			}
		});
		$(this).parent().parent().parent().removeClass('notComprareThis');
		if(flag) {
			$(".f-input-li").css("display","none");
			$(this).parent().parent().parent().find('input:text,input:hidden').val('').removeClass("n-invalid");
			$(this).parent().parent().parent().find(".g-wmfinp-warning").css("display","none");
			$(this).parent().parent().parent().find(".g-wmfinp-danger").css("display","none");
			return false;
		}
		
		if(str[2]==1) {
			$(this).parent().parent().find('[name="zhensuojcxid"]').val(str[1]);
			$(this).parent().parent().parent().find('[name="jine"]').attr('readOnly','true');
		}else{
			$(this).parent().parent().find('[name="pingtaijcxid"]').val(str[1]);
		}
		
		
		if(str[0]!="") {
			$(this).parent().parent().parent().find('.jine').val(parseFloat(roundUtil(parseFloat(str[0]), 8)));
		}else{
			$(this).parent().parent().parent().find('.jine').val(0.00);
		}
		
		$(this).parent().parent().find(".dropdowninput").val(bText).removeClass("n-invalid");
		$(this).parent().siblings('#jianchaName').addClass('isChose');
		$(".f-input-li").css("display","none");
		$('#hz_serch').val("");
		$(this).parent().text("");
		jisuanYmje();
	});
	
	//点击耗材li
	$(document).on("click",".haocai li.xuanzeli",function(){
		$(this).parent().parent().parent().find('[name="jine"]').removeAttr('readOnly');
		$(this).parent().parent().parent().find('[name="danwei"]').removeAttr('readOnly');
		$(this).parents('tr').find('input:text,input:hidden').val('').removeClass("n-invalid");
		$(this).parent().parent().parent().find(".g-wmfinp-warning").css("display","none");
		$(this).parent().parent().parent().find(".g-wmfinp-danger").css("display","none");
		xuanzeypFlag = true;
		var bText = $(this).text();
		var str = $(this).attr('index').split(',');
		var uuid = $(this).attr('uuid');
		var iszs = str[5];
		if(iszs == 0) {
			var haocai = getHaocaixq(str[2],iszs);
		}else{
			var haocai = getHaocaixq(uuid,iszs);
		}
		
		$(this).parent().parent().parent().addClass('notComprareThis');//给当前行加上一个标记
		var flag;
		$(this).parent().parent().parent().parent().find('[name="zhensuohcid"]').each(function(){
			if(!$(this).parent().parent().hasClass('notComprareThis')) {//当前行不比较
				if(str[5]==0&&str[2]==$(this).val()){
					notifyWarning('请不要添加重复耗材');
					flag = true;
					return false;
				}
			}
		});
		$(this).parent().parent().parent().parent().find('[name="pingtaihcid"]').each(function(){
			if(!$(this).parent().parent().hasClass('notComprareThis')) {
				if(str[5]==1&&str[2]==$(this).val()){
					notifyWarning('请不要添加重复耗材');
					flag = true;
					return false;
				}
			}
		});
		$(this).parent().parent().parent().removeClass('notComprareThis');
		if(flag) {
			$(".f-input-li").css("display","none");
			$(this).parent().parent().parent().find('input:text,input:hidden').val('').removeClass("n-invalid");
			$(this).parent().parent().parent().find(".g-wmfinp-warning").css("display","none");
			$(this).parent().parent().parent().find(".g-wmfinp-danger").css("display","none");
			return false;
		}
		$(this).parent().parent().parent().find('[name="danjia"]').val(str[0]);
		$(this).parent().parent().parent().find('[name="chailingsl"]').val(str[8]);
		$(this).parent().parent().parent().find('[name="baozhuangdw"]').val(str[1]);
		$(this).parent().parent().parent().find('[name="kucunsl"]').val(str[9]);
		$(this).parent().parent().parent().find('[name="tiaoxingma"]').val(str[10]);
		fillHaocai(haocai,this,iszs);
		jisuanYmje();
	});
	
	//耗材金额计算
	function jisuanhcje(obj) {
		var shuliang = $(obj).val();
		var danjia = $(obj).parent().parent().find('[name="danjia"]').val();
		var haocaidwul = $(obj).parent().parent().find('.hcdanwei');
		var haocaidwli = haocaidwul.find('li');
		var danwei = $(obj).parent().parent().find('[name="danwei"]').val();
		var baozhuangdw = $(obj).parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(obj).parent().parent().find('[name="chailingsl"]').val();
		var kucunsl = $(obj).parent().parent().find('[name="kucunsl"]').val();
		
		if(danjia!==""&&danjia!=="null"&&isZhengzs(shuliang)) { // 所有的金额都为单价，不用计算金额（改版啦）
			if(shuliang!="") {
				if(Number(kucunsl)< Number(shuliang)) { // 库存不足提示
					$(obj).parent().parent().find('.g-wmfinp-warning').css('display','block');
					$(obj).parent().parent().find('.g-wmfinp-warning').attr('data-content','该耗材库存不足');
				}else{
					$(obj).parent().parent().find('.g-wmfinp-warning').css('display','none');
				}
				if(haocaidwli.length==2&&danwei==baozhuangdw) { // 支持拆零且选择的是包装单位
					danjia = multiply(danjia, chailingsl);
				}
			}
		}
	}
	//耗材单位blur事件
	$(document).on('blur','#cghc-fydw',function(){
		var shuliang = $(this).parent().find('[name="shuliang"]').val();
		var danjia = $(this).parent().parent().find('[name="danjia"]').val();
		var danwei = $(this).val();
		var baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
		var pingtaihcid = $(this).parent().parent().find('[name="pingtaihcid"]').val();
		var chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
		var kucunsl = $(this).parent().parent().find('[name="kucunsl"]').val();
		var uuid = $(this).parent().parent().find('[name="ptuuid"]').val();
		var zhensuohcid = $(this).parent().parent().find('[name="zhensuohcid"]').val();
		if (!zhensuohcid) {
			var haocai = getHaocaixq(uuid,1);
			var haocai = compareZsHaoCaiBykydw(haocai.mingcheng,haocai.baozhuanggg,danwei,haocai);
			if(!!haocai) {
				var str = '<li style="display:none"></li>';
				$(this).parents('tr').find('.haocai').append(str);
				fillHaocai(haocai,$(this).parents('tr').find('.haocai').find('li'),0,danwei);
				var haocaidwli =$(this).siblings('.hcdanwei').find('li');
				var danjia = $(this).parent().parent().find('[name="danjia"]').val();
				var baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
				var chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
				
				if(haocaidwli.length==2 && danwei == baozhuangdw) {//支持拆零且选择的是包装单位
					var baozhuangjia = multiply(danjia, chailingsl);
					$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(baozhuangjia, 8))).removeClass("n-invalid");
				} else {
					$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(parseFloat(danjia), 8))).removeClass("n-invalid");
				}
			}
		}
		var chailingbz = $(this).parent().parent().find('[name="chailingbz"]').val();
		if(!!danjia) {//当有单价时才计算
			if(shuliang!="") {
				if(chailingbz == 1 && danwei==baozhuangdw) {//支持拆零且选择的是包装单位
					danjia = multiply(danjia, chailingsl);
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().find('.g-wmfinp-warning').attr('data-content','该耗材库存不足');
					}else{
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
				$(this).parent().parent().find('[name="jine"]').removeClass("n-invalid");
			}
		}
		$(this).parent().trigger("click");  //触发总价格变化
	});  
	//耗材单位选择事件
	$(document).on('click','.hcdanwei li',function(){
		var shuliang = $(this).parent().parent().find('[name="shuliang"]').val();
		var danjia = $(this).parent().parent().parent().find('[name="danjia"]').val();
		var haocaidwul = $(this).parent();
		var haocaidwli = haocaidwul.find('li');
		var danwei = $(this).text();
		var baozhuangdw = $(this).parent().parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(this).parent().parent().parent().find('[name="chailingsl"]').val();
		var kucunsl = $(this).parent().parent().parent().find('[name="kucunsl"]').val();
		var uuid = $(this).parent().parent().parent().find('[name="ptuuid"]').val();
		var pingtaihcid = $(this).parent().parent().parent().find('[name="pingtaihcid"]').val();
		if (!!pingtaihcid) {
			var haocai = getHaocaixq(uuid,1);
			var haocai = compareZsHaoCaiBykydw(haocai.mingcheng,haocai.baozhuanggg,danwei,haocai);
			if(!!haocai) {
				var str = '<li style="display:none"></li>';
				$(this).parents('tr').find('.haocai').append(str);
				fillHaocai(haocai,$(this).parents('tr').find('.haocai').find('li'),0);
			}
		}
		if(danjia!=""&&danjia!="null"&&danjia!=0) {//当有单价时才计算
			if(haocaidwli.length==2 && danwei == baozhuangdw) {//支持拆零且选择的是包装单位
				var baozhuangjia = multiply(danjia, chailingsl);
				$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(baozhuangjia, 8))).removeClass("n-invalid");
			} else {
				$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(parseFloat(danjia), 8))).removeClass("n-invalid");
			}
			if(shuliang!="") {
				if(haocaidwli.length==2&&danwei==baozhuangdw) {//支持拆零且选择的是包装单位
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().parent().find('.g-wmfinp-warning').attr('data-content','该耗材库存不足');
					}else{
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
			}
		}
		$(this).parent().parent().trigger("click");  //触发总价格变化
	});
	
	//点击用药频率li
	$(document).on("click",".yongyyaoplul li",function(){
		var bText = $(this).attr('index');
		$(this).parent().parent().find('.yongyypl').val(bText).removeClass("n-invalid");
		
		$(".f-input-li").css("display","none");
		$('#hz_serch').val("");
		$(this).parent().parent().parent().parent().find("input:visible:not('.wm-group')").each(function(){
			if($(this).val()==""){
				$(this).focus();
				return false;
			}
		})
		$(this).parent().text("");
	});
	
	//点击用法li
	$(document).on("click",".yongfaul li",function(){
		var bText = $(this).text();
		$(this).parent().parent().find('.yongfa').val(bText).removeClass("n-invalid");
		
		$(".f-input-li").css("display","none");
		$('#hz_serch').val("");
	    $(this).parent().parent().parent().parent().find("input:visible:not('.wm-group')").each(function(){
			if($(this).val()==""){
				$(this).focus();
				return false;
			}
		})
		$(this).parent().text("");
	});
	
	//智能诊断查询
	function getzhinengzd() {
		var senddata={
			'zhushu':$('#first-info').val(),
			'tiwen':$('#input-body-temperature').val(),
			'tizhong':$('#input-body-weight').val(),
			'xinlv':$('#input-heart-rate').val(),
			'shousuoya':$('#input-heart-pressure').val(),
			'shuzhangya':$('#input-heart-pressure2').val(),
		};
		$.ajax({
	        type:"POST",
	        url:"./changguimz/getzhinengzd",
	        data:senddata,
	        success: function(data){
	        	if(data!="") {
	        		$('.radio').css('display','none');
	        		$('.ckbs-box').css('display','none');
	        		var zhinengzdstr = '';
	        		$(data).each(function(i,e){
	        			zhinengzdstr += '<div class="changjzd">'+
	        			'<p class="pzhizhengzd"><span iszs="0" index="'+this.jibingid +'"jibingid="'+this.jibingid + '"icd10="' + this.icd10 + '"jibingmc="' + this.jibingmc +'" class="left changjzd-top" type="checkbox">' + this.jibingmc + ' ' + this.icd10 + '</span><span class="right">【更多】</span></p>'+
	        			'<ul>';
	        			var zhushufc = this.zhushufc;
	        			var zhushufcArry = zhushufc.split(',');
	        			for(var i = 0; i < zhushufcArry.length; i++) {
	        				if(i != zhushufcArry.length-1){
	        					zhinengzdstr += '<li>'+zhushufcArry[i]+',</li>';
	        				}else if(i == zhushufcArry.length-1){
	        					zhinengzdstr += '<li>'+zhushufcArry[i]+'</li>';
	        				}
	        			}
	        			zhinengzdstr +='</ul>'+
	        			'</div>';
	        		});
	        		
	        		var img ='<img src="'+path+'/image/changgmz/cgmz-light.gif"/>';
	        		$('.zhenduan-content').html(zhinengzdstr);
	        		$('.cgmz-znzd-nav').css({'background':'#1ebdff','border-color':'#1ebdff'});
	        		var hello = $('.cgmz-znzd-nav').find('img');
        			if(hello.length<1){
        				$('.cgmz-znzd-nav').prepend(img);
        			}
	        	}else{
	        		//恢复原样
	        		$('.cgmz-znzd-nav').css({'background':'#009943','border-color':'#009943'});
	        		$('.cgmz-znzd-nav img').remove();
	        		$('.radio').css('display','none');
	        		$('.moren').css('display','inline-block');
	        	}
	        }
		});
	}
	
	//智能诊断点击事件
	$("#btnConfirm").click(function(){
		$(this).parent().parent().find('.left').each(function(i,tdiv){
			if($(this).hasClass('changjzd-bottom')) {
				var jibingid = $(this).attr("jibingid");
				var content = $(this).text();
				var icd10 = $(this).attr("icd10");
				console.log(icd10)
				var zhenduanstr = getZhenduanstr();
				if(content!=''){
					if(zhenduanstr.indexOf(content) >= 0) {
					}else{
						var increase = '<span iszs="0" index="'+jibingid+'"jibingid="'+jibingid+'" class="cgmz-l2zd-dropmain">'+content +'<span class="cgmz-l2zd-dropimg"></span></span>';
						
						$('.cgmz-l2zd-dropdown').append(increase);
					}
				}
			}
			
			
		});
		$('.routine-diagnosis').css('display','none');
		return false;
	});
	//点击查看病史
	$(".btn-ckbs").click(function(){
		$('.ckbs-box').css('display','block');
		var h1= $(".routine-diagnosis").height();
		var h2=$(".ckbs-main-content").height();
		var h3=$(".ckbs-main-content").css("height",(h1-50)+"px");
	});
	
	//点击诊断li
	$(document).on("click",".cgmz-zhend-ul li",function(){
		var bText = $(this).text().trim().substr(0,128);
		var btext = bText.replace(/\s/g, "");
		var zhenduanstr = getZhenduanstr();
		var str = '';
		if(zhenduanstr != ''){
			str = zhenduanstr.split(':');
			str = str[0] + str[1];
		}
		if(str.indexOf(btext) >= 0 && str != '') {
		}else{
			var str = '<span index="'+$(this).attr("index")+'" iszs="'+$(this).attr("iszs")+'" class="cgmz-l2zd-dropmain">'+bText+'<span class="cgmz-l2zd-dropimg"></span></span>';
			$('.cgmz-l2zd-dropdown').append(str);
		}
		$(this).parent().parent().find('#input-diagnosis').val("");
		$(".cgmz-zhend-ul").css("display","none").text("");
		$('#hz_serch').val("");
	});
	//诊断鼠标离开
	var zhenduanFlag = true;
	// 常规门诊、微诊疗诊断blur事件
	function zhenduanBlur(obj){
		var jibingmcli = $(obj).parent().find('.hello');
		var val = $(obj).val();
		if(jibingmcli.length < 1) {
			if(val!=''&&zhenduanFlag) {
				$(obj).focus();
				notifyWarning('请从诊所库存或者平台病库中选择病种！');
				return false;
			}
		}
	}
	$('#input-diagnosis').blur(function(){
		var zhenduanstr = getZhenduanstr();
		$(this).parent().find('li').each(function(){
			if($(this).hasClass('hello')) {
				zhenduanFlag = false;
			}
		});
		if(zhenduanFlag) { 
			zhenduanBlur(this);
			/*var bText = $(this).val().trim().substr(0,128);
			if(bText != '') {
				if(zhenduanstr.indexOf(bText) < 0) {
					var str = '<span class="cgmz-l2zd-dropmain">'+bText+'<span class="cgmz-l2zd-dropimg"></span></span>';
					$('.cgmz-l2zd-dropdown').append(str);
				}
			}*/
			$(this).parent().parent().find('#input-diagnosis').val("");
			$(this).parent().find(".cgmz-zhend-ul").html("");
		}
		zhenduanFlag = true;
	});
	//诊断上下键选择后能再次触发下拉效果
	$('#input-diagnosis').keyup(function(){
		getJibingml(this);
		$('.cgmz-zhend-ul').css('display','block');
	});
	//将诊断信息拼接成字符串格式，用逗号隔开
	function getZhenduanstr(){
		var str = '';
		var cgmzZd = $('#cgmz-zd-dropdown').children();
		$('.cgmz-l2zd-dropdown').find('.cgmz-l2zd-dropmain').each(function(index,element){
			var s = $(this).text().split(/\s+/);
			if(index==0) {
				if(!!cgmzZd.eq(index).attr('iszs')){
					str += s[0] + ':' + s[1] + ':' + cgmzZd.eq(index).attr('iszs') + ':' + cgmzZd.eq(index).attr('index');
				}else{
					str += s[0] + ':' + s[1];
				}
			}else{
				if(!!cgmzZd.eq(index).attr('iszs')){
					str += ',' + s[0] + ':' + s[1] + ':' + cgmzZd.eq(index).attr('iszs') + ':' + cgmzZd.eq(index).attr('index');
				}else{
					str += ',' + s[0] + ':' + s[1];
				}
			}
		});
		return str;
	}
	//检查项blur事件
	var jianchaxiangFlag = true;
	/**
	 * @Description: 
	 * @param obj
	 * @returns {Boolean}
	 */ 
	function jianchaxiangBlur(obj){
		var jianchamcli = $(obj).hasClass('isChose');
		var val = $(obj).val();
		if(!jianchamcli) {
			if(val!=''&&jianchaxiangFlag) {
				$(obj).focus();
				notifyWarning('请从诊所库存中选择诊疗项目！');
				return false;
			}
		}
	}
	
	$(document).on('blur','#jianchaName',function(){
		var thisValue = $(this).val();
		var isChose = $(this).parent().find('li');
		if(isChose.hasClass('hello')) {
			jianchaxiangFlag = false;
		}
		if(jianchaxiangFlag&&thisValue!="") { 
			var _that = this;
				jianchaxiangBlur(_that);
				xuanzeypFlag = false;
		}else{
			xuanzeypFlag = true;
		}
		jianchaxiangFlag = true;
	});
	//点击药品名称li
	$(document).on("click",".yaopinmcul li.xuanzeli",function(event){
		var id = $(this).attr('index');
		var iszs = $(this).attr('iszs');
		var yaopin = getYaopinById(id,iszs);
		fillYaopin(yaopin,this,iszs);
		jisuanYmje();
	});
	//成药选择框后的bulr事件
	
	//计算药品价格
	function jisuanypje(obj) {
		var shuliang = $(obj).val();
		var danjia = $(obj).parent().parent().find('[name="danjia"]').val();
		var kaiyaodwul = $(obj).parent().parent().find('.kaiyaodw');
		var kaiyaodwli = kaiyaodwul.find('li');
		var kaiyaodw = $(obj).parent().parent().find('[name="kaiyaodw"]').val()||$(obj).parent().parent().find('[name="danwei"]').val();
		var baozhuangdw = $(obj).parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(obj).parent().parent().find('[name="chailingsl"]').val();
		var kucunsl = $(obj).parent().parent().find('[name="kucunsl"]').val();
		var tieshu = $(obj).parent().parent().parent().parent().parent().parent().find('[name="tieshu"]').val();
		var zhensuoypid = $(this).parent().parent().find('[name="zhensuoypid"]').val();
		
//		if(tieshu!='undefined'&&shuliang!=""&&tieshu!=undefined&&isZhengzs(shuliang)) {
//			var zje = $(obj).parent().parent().find('[name="jine"]').val();
//			if(zje!=''&&zje!=null&&zje!='0.00') {
//				if(zhensuoypid==''||zhensuoypid=='null') {
//					var tsdanjia = parseFloat(zje)/ parseFloat(shuliang);
//                    var str = '单价('+tsdanjia.toFixed(2)+')=金额('+zje+')÷数量('+shuliang+')';
//					$(obj).parent().parent().find('[name="jine"]').attr('data-content',str);
//				}
//			}
//			shuliang = parseFloat(shuliang);
//		}
		if(danjia!=""&&danjia!="null"&&danjia!=0&&isZhengzs(shuliang)) {//当有单价时才计算
			if(shuliang!="") {
				if(kaiyaodwli.length==2&&kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
						danjia = multiply(danjia, chailingsl);
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(obj).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(obj).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(obj).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(obj).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(obj).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}else{
					if(Number(kucunsl)< Number(shuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(obj).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(obj).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(obj).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(obj).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(obj).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
				var jine = multiply(shuliang, danjia);
//				$(obj).parent().parent().find('[name="jine"]').val(jine.toFixed(2));
			}else {
//				$(obj).parent().parent().find('[name="jine"]').val(0.00);
			}
		}
	}
	
	$(document).on('focusin keyup','[name="danjiliang"]',function(){
		var danjijine = $(this).parent().parent().find('[name="jine"]');
		var weishutongji = ($(this).parent().parent().find('[name="jine"]').val());
		var zje = $(this).parent().parent().find('[name="jine"]').val();
		var tieshu = $(this).parent().parent().parent().parent().parent().parent().find('[name="tieshu"]').val();
		var shuliang = $(this).val();
		var zhensuoypid = $(this).parent().parent().find('[name="zhensuoypid"]').val();
//		if(tieshu!='undefined'&&tieshu!=undefined) {
//			if(zhensuoypid==''||zhensuoypid=='null'||zhensuoypid==null) {
//				if(shuliang!=''&&zje!=''&&zje!='0.00') {
//                    var tsdanjia = parseFloat(zje)/ parseFloat(shuliang);
//                    var str = '单价('+tsdanjia.toFixed(2)+')=金额('+zje+')÷数量('+shuliang+')';
//				}else{
//					var str = '金额=单价*数量';
//				}
//				danjijine.attr('data-content',str);
//			}
//		}
	});
	
	$(document).on('focusin keyup','[name="jine"]',function(){
		danjijine($(this));
		weishutongji($(this));
		var zje = $(this).val();
		var tieshu = $(this).parent().parent().parent().parent().parent().parent().find('[name="tieshu"]').val();
		var shuliang = $(this).parent().parent().find('[name="danjiliang"]').val();
		var zhensuoypid = $(this).parent().parent().find('[name="zhensuoypid"]').val();
//		if(tieshu!='undefined'&&tieshu!=undefined) {
//			if(zhensuoypid==''||zhensuoypid=='null'||zhensuoypid==null) {
//				if(shuliang!=''&&zje!=''&&zje!='0.00') {
//                    var tsdanjia = parseFloat(zje)/ parseFloat(shuliang);
//                    var str = '单价('+tsdanjia.toFixed(2)+')=金额('+zje+')÷数量('+shuliang+')';
//				}else{
//					var str = '金额=单价*数量';
//				}
//				$(this).attr('data-content',str);
//			}
//		}
	});
	//开药单位blur事件
	$(document).on('blur','.chinese-medicine [name="danwei"]',function () {
		var shuliang = $(this).parent().find('[name="kaiyaoliang"]').val()||$(this).parent().find('[name="danjiliang"]').val();
		var danjia = $(this).parent().parent().find('[name="danjia"]').val();
		var kaiyaodwul = $(this).siblings('.kaiyaodw');
		var kaiyaodwli = kaiyaodwul.find('li');
		var kaiyaodw = $(this).val() || $(this).parent().find('[name="danwei"]').val();
		var baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
		var chailingdw = $(this).parent().parent().find('[name="chailingdw"]').val();
		var kucunsl = $(this).parent().parent().find('[name="kucunsl"]').val();
		var tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
		var pingtaiypid = $(this).parent().parent().find('[name="pingtaiypid"]').val();
		var zhensuoypid = $(this).parent().parent().find('[name="zhensuoypid"]').val();
		var uuid = $(this).parent().parent().find('[name="ptuuid"]').val();
		var jine = '';
		var bText = $(this).text();
		    $(this).removeClass("n-invalid");
		    $(this).parent(".dropdown-menu").css("display","none");
		    //$(this).parent().parent().parent().find('[name="danwei"]').val(bText);
		if (!zhensuoypid) {
			var ptyaopin = getYaopinById(uuid,1);
			var yaopin = compareYaopinBykydw(ptyaopin.mingcheng,ptyaopin.baozhuanggg,kaiyaodw,ptyaopin);
			if(!!yaopin) {
				var str = '<li style="display:none">1</li>';
				$(this).parents('tr').find('.yaopinmcul').append(str);
				fillYaopin(yaopin,$(this).parents('tr').find('.yaopinmcul li'),0,kaiyaodw);
				shuliang = $(this).parent().find('[name="kaiyaoliang"]').val()||$(this).parent().find('[name="danjiliang"]').val();
				danjia = $(this).parent().parent().find('[name="danjia"]').val();
				kaiyaodwul = $(this).siblings('.kaiyaodw');
				kaiyaodwli = kaiyaodwul.find('li');
				kaiyaodw = $(this).val();
				baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
				chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
				chailingdw = $(this).parent().parent().find('[name="chailingdw"]').val();
				kucunsl = $(this).parent().parent().find('[name="kucunsl"]').val();
				tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
				pingtaiypid = $(this).parent().parent().find('[name="pingtaiypid"]').val();
				jine = '';
			}
		}
		if(danjia!=""&&danjia!="null"&&danjia!=0) {//当有单价时才计算
			if(kaiyaodwli.length==2 && kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
				var	baozhuangjia = multiply(danjia, chailingsl);
				$(this).parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(baozhuangjia, 8)));
			} else {
				$(this).parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(parseFloat(danjia), 8)));
			}
			if(shuliang!="") {
				danjijine($(this));
				weishutongji($(this));
				if(kaiyaodwli.length==2&&kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}else{
					if(Number(kucunsl)< Number(shuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger == 'block'){
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
			}
		}
		$(this).parent().parent().trigger("click");  //触发总价格变化
	});
	//开药单位blur事件
	$(document).on('blur','[name="kaiyaodw"]',function () {
		var shuliang = $(this).parent().find('[name="kaiyaoliang"]').val()||$(this).parent().find('[name="danjiliang"]').val();
		var danjia = $(this).parent().parent().find('[name="danjia"]').val();
		var kaiyaodwul = $(this).siblings('.kaiyaodw');
		var kaiyaodwli = kaiyaodwul.find('li');
		var kaiyaodw = $(this).val() || $(this).parent().find('[name="danwei"]').val();
		var baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
		var chailingdw = $(this).parent().parent().find('[name="chailingdw"]').val();
		var kucunsl = $(this).parent().parent().find('[name="kucunsl"]').val();
		var tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
		var pingtaiypid = $(this).parent().parent().find('[name="pingtaiypid"]').val();
		var zhensuoypid = $(this).parent().parent().find('[name="zhensuoypid"]').val();
		var uuid = $(this).parent().parent().find('[name="ptuuid"]').val();
		var jine = '';
		var bText = $(this).text();
		    $(this).removeClass("n-invalid");
		    $(this).parent(".dropdown-menu").css("display","none");
		    //$(this).parent().parent().parent().find('[name="danwei"]').val(bText);
		if (!zhensuoypid) {
			var ptyaopin = getYaopinById(uuid,1);
			var yaopin = compareYaopinBykydw(ptyaopin.mingcheng,ptyaopin.baozhuanggg,kaiyaodw, ptyaopin);
			console.log(yaopin)
			if(!!yaopin) {
				var str = '<li style="display:none">1</li>';
				$(this).parents('tr').find('.yaopinmcul').append(str);
				fillYaopin(yaopin,$(this).parents('tr').find('.yaopinmcul li'),0,kaiyaodw);
				shuliang = $(this).parent().find('[name="kaiyaoliang"]').val()||$(this).parent().find('[name="danjiliang"]').val();
				danjia = $(this).parent().parent().find('[name="danjia"]').val();
				kaiyaodwul = $(this).siblings('.kaiyaodw');
				kaiyaodwli = kaiyaodwul.find('li');
				kaiyaodw = $(this).val();
				baozhuangdw = $(this).parent().parent().find('[name="baozhuangdw"]').val();
				chailingsl = $(this).parent().parent().find('[name="chailingsl"]').val();
				chailingdw = $(this).parent().parent().find('[name="chailingdw"]').val();
				kucunsl = $(this).parent().parent().find('[name="kucunsl"]').val();
				tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
				pingtaiypid = $(this).parent().parent().find('[name="pingtaiypid"]').val();
				jine = '';
			}
		}
		if(danjia!=""&&danjia!="null"&&danjia!=0) {//当有单价时才计算
			if(kaiyaodwli.length==2 && kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
				var	baozhuangjia = multiply(danjia, chailingsl);
				$(this).parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(baozhuangjia, 8)));
			} else {
				$(this).parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(parseFloat(danjia), 8)));
			}
			if(shuliang!="") {
				danjijine($(this));
				weishutongji($(this));
				if(kaiyaodwli.length==2&&kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}else{
					if(Number(kucunsl)< Number(shuliang)) {//库存不足提示
						var danger = $(this).parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger == 'block'){
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
			}
		}
		$(this).parent().parent().trigger("click");  //触发总价格变化
	});
	//开药单位选择事件
	$(document).on('click','.kaiyaodw li',function(){
		var shuliang = $(this).parent().parent().find('[name="kaiyaoliang"]').val()||$(this).parent().parent().find('[name="danjiliang"]').val();
		var danjia = $(this).parent().parent().parent().find('[name="danjia"]').val();
		var kaiyaodwul = $(this).parent();
		var kaiyaodwli = kaiyaodwul.find('li');
		var kaiyaodw = $(this).text()||$(this).parent().parent().find('[name="danwei"]').val();
		$(this).parent().parent().parent().find('[name="danwei"]').val(kaiyaodw);
		var baozhuangdw = $(this).parent().parent().parent().find('[name="baozhuangdw"]').val();
		var chailingsl = $(this).parent().parent().parent().find('[name="chailingsl"]').val();
		var kucunsl = $(this).parent().parent().parent().find('[name="kucunsl"]').val();
		var tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
		var pingtaiypid = $(this).parent().parent().parent().find('[name="pingtaiypid"]').val();
		var uuid = $(this).parent().parent().parent().find('[name="ptuuid"]').val();
		$(this).parent().siblings('.cgmdc-input62').removeClass("n-invalid");
		if (!!pingtaiypid) {
			var ptyaopin = getYaopinById(uuid,1);
			var yaopin = compareYaopinBykydw(ptyaopin.mingcheng,ptyaopin.baozhuanggg,kaiyaodw,ptyaopin);
			if(!!yaopin) {
				var str = '<li style="display:none"></li>';
				$(this).parents('tr').find('.yaopinmcul').append(str);
				fillYaopin(yaopin,$(this).parents('tr').find('.yaopinmcul').find('li'),0);
				
				shuliang = $(this).parent().parent().find('[name="kaiyaoliang"]').val()||$(this).parent().parent().find('[name="danjiliang"]').val();
				danjia = $(this).parent().parent().parent().find('[name="danjia"]').val();
				kaiyaodwul = $(this).parent();
				kaiyaodwli = kaiyaodwul.find('li');
				kaiyaodw = $(this).text() || $(this).parent().parent().find('[name="danwei"]').val();
				baozhuangdw = $(this).parent().parent().parent().find('[name="baozhuangdw"]').val();
				chailingsl = $(this).parent().parent().parent().find('[name="chailingsl"]').val();
				chailingdw = $(this).parent().parent().parent().find('[name="chailingdw"]').val();
				kucunsl = $(this).parent().parent().parent().find('[name="kucunsl"]').val();
				tieshu = $(this).parents('#chinese-medicine').find('[name="tieshu"]').val();
				pingtaiypid = $(this).parent().parent().parent().find('[name="pingtaiypid"]').val();
				jine = '';
			}
		}
		if(danjia!=""&&danjia!="null"&&danjia!=0) {//当有单价时才计算
			if(kaiyaodwli.length==2 && kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
				var	baozhuangjia = multiply(danjia, chailingsl);
				$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(baozhuangjia, 8)));
			} else {
				$(this).parent().parent().parent().find('[name="jine"]').val(parseFloat(roundUtil(parseFloat(danjia), 8)));
			}
			if(shuliang!="" &&isZhengzs(shuliang)) {
				danjijine($(this));
				weishutongji($(this));
				if(kaiyaodwli.length==2&&kaiyaodw==baozhuangdw) {//支持拆零且选择的是包装单位
					var zongshuliang = multiply(shuliang, chailingsl);
					if(Number(kucunsl)< Number(zongshuliang)) {//库存不足提示
						var danger = $(this).parent().parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(this).parent().parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}else{
					if(Number(kucunsl)< Number(shuliang)) {//库存不足提示
						var danger = $(this).parent().parent().parent().find('.g-wmfinp-danger').css("display");
						if(danger=='block'){
							$(this).parent().parent().parent().find('.g-wmfinp-warning').css('right','35px');
						}else{
							$(this).parent().parent().parent().find('.g-wmfinp-warning').css('right','12px');
						}
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','block');
						$(this).parent().parent().parent().find('.g-wmfinp-warning').attr('data-content','该药材库存不足');
					}else{
						$(this).parent().parent().parent().find('.g-wmfinp-warning').css('display','none');
					}
				}
			}
		}
		$(this).parent().parent().trigger("click");  //触发总价格变化
	});
	
	//计算草药价格
	function jiasuancaoyao(obj) {
		var tieshu = $(obj).val();
		 $(obj).parent().parent().parent().find('[name="danjia"]').each(function(){
			 	var kaiyaodw = $(this).parent().find('[name="danwei"]').val();
				var baozhuangdw = $(this).parent().find('[name="baozhuangdw"]').val();
				var chailingsl = $(this).parent().find('[name="chailingsl"]').val();
				var kaiyaodwli = $(this).parent().find('.kaiyaodw li');
			 if($(this).val()!=0) {
				 var shuliang = $(this).parent().find('[name="danjiliang"]').val();
				 if(shuliang!=''&&isZhengzs(tieshu)) {
					 if(kaiyaodwli.length==2&&kaiyaodw==baozhuangdw) {
						 var jine =  multiply(multiply(shuliang, $(this).val()), chailingsl);
					 } else {
						 var jine =  multiply(shuliang, $(this).val());
					 }
//					 $(this).parent().find('[name="jine"]').val(jine.toFixed(2));
				 }else{
//					 $(this).parent().find('[name="jine"]').val('0.00');
				 }
			 }
		 });
	}
	
	$(document).on('focusin keyup blur','[name="danjiliang"]',function(){
		if($(this).val != ''){
			danjijine($(this));
			weishutongji($(this));
		}
	});
	$(document).on('focusin keyup blur','[name="yaopinmc"]',function(){
			danjijine($(this));
			weishutongji($(this));
			
	})
	$(document).on('focusin keyup blur','[name="tieshu"]',function(){
			danjijine($(this));
			weishutongji($(this));
			
	})
	function danjijine(obj){
		var sum = 0;
		var danjizje = 0;
		var tieshu = obj.parents(".chinese-medicine").find("input[name='tieshu']").val();
		obj.parents(".chinese-medicine").find("input[name='jine']:not(last)").each(function(){
			var shuliang = $(this).parent().parent().find("[name='danjiliang']").val();
			danjizje += multiply($(this).val(), shuliang);
		});
		if(tieshu != ''){
			sum = multiply(danjizje, tieshu);
		}
		if(danjizje){
			obj.parents(".chinese-medicine").find('.danjizongje').text(roundUtil(danjizje, 2)+'元');
		}else{
			obj.parents(".chinese-medicine").find('.danjizongje').text('0.00元');
		}
		if(sum){
			obj.parents(".chinese-medicine").find('.chufangzje').text(roundUtil(sum, 2)+'元');
		}else{
			obj.parents(".chinese-medicine").find('.chufangzje').text('0.00元');
		}
		
	}
	
	function weishutongji(obj){
		var index = 0;
		var trlen = obj.parents(".chinese-medicine").find("[name='yaopinmc']");
		trlen.each(function(){
			if($(this).val() != ''){
				index += 1;
			} 
			if($(this).val() == trlen.val()){
				index;
			}
			$(this).parents(".chinese-medicine").find(".yaopingsl").text(index);
		});
	}
	
	//用法点击聚焦事件
	$(document).on('focusin','.yongfa',function(){
		var jixing = $(this).parent().parent().find('[name="jixing"]').val();
		getYongfazd(this,jixing);
	});
	
	//引用常用处方
	$('.add-common').click(function() {
		chufanglx = null;
		getChangyongcf(chufanglx)
	});
	function getChangyongcf(chufanglx){
		$.ajax({
		    type:"POST",
		    url:'./changguimz/getChangyongcf',
		    data:{leixing:chufanglx},
		    success:function(data){
		    	$('#changyongcf').html("");
				if(data!="") {
					$(data).each(function(i) {
						index= i+1;
						var leixing = this.leixing;
						if(leixing==1) {
							leixing = '成药';
						}else if(leixing==2){
							leixing = '草药';
						}
						var content;
						if(i==0){
							content = '<tr class="cgmz-tr-radio">';
							content += '<td class="col-sm-3"><span id="chufmc" style="margin-left: 17px;">处方名称</span><span id="chufmc">创建人</span><span style="float:right; margin-right:40px;line-height: 40px;">类型</span></label></td>';
							content += '</tr>';
						}
						content += '<tr class="cgmz-tr-radio">';
						content += '<td class="col-sm-3"><input type="checkbox" name="nixie" id="cycf'+index+'" leixing='+this.leixing+' index='+this.chufangmbid+' style="display:none";><label class="cymb-check1 oncymb-check1" for="cycf'+index+'"><span id="chufmc">'+this.mobanmc+'</span><span id="chufmc">'+this.xingming+'</span><span style="float:right; margin-right:40px;line-height: 40px;">'+leixing+'</span></label></td>';
						content += '</tr>';
						$('#changyongcf').append(content);
					});
					$("#mymodal-data").modal();
				}else{
					if(chufanglx==null) {
						notifyInfo("您还没维护处方");
					}else if(chufanglx==1) {
						notifyInfo("您还没维护成药处方");
					}else if(chufanglx==2) {
						notifyInfo("您还没维护草药处方");
					}
				}
				
			}
		});
		$("#mymodal-data .button-box ul li").removeClass("xuanzhong");
		$("#btnQuanbu").addClass("xuanzhong");
	}
	var chufanglx = null;
	//常用处方点击条件
	$("#btnQuanbu").click(function(){
		chufanglx = null;
		getChangyongcf(chufanglx);
		$("#mymodal-data .button-box ul li").removeClass("xuanzhong");
		$(this).addClass("xuanzhong");
	});
	$('#btnChengyao').click(function(){
		chufanglx = 1;
		getChangyongcf(chufanglx);
		$("#mymodal-data .button-box ul li").removeClass("xuanzhong")
		$(this).addClass("xuanzhong");
	});
	$('#btnCaoyao').click(function(){
		chufanglx = 2;
		getChangyongcf(chufanglx)
		$("#mymodal-data .button-box ul li").removeClass("xuanzhong")
		$(this).addClass("xuanzhong");
	});
	
	//点击常用处方保存
	$(document).on('click','#btnchangyongcf',function(){
		$('input:checkbox[name=nixie]:checked').each(function(i,e){
			var id = $(this).attr('index');
			var leixing = $(this).attr('leixing');
			
			if(leixing==1) {//成药
				$.ajax({
				    type:"POST",
				    url:'./changguimz/getExChengyaopy',
				    data:{id:id},
				    success:function(data){
						if(data!="") {
							var len=$(".western-medicine").length;
							var kelong= '<div class="western-medicine g-m-west">'+
						    ' <div class="chinese-head">成药处方'+(len)+'<span class="medicine-delete">删除处方</span></div>'+
						    '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
					        '<input type="hidden" style="display:none;" name="mingcheng" value="'+"成药处方"+(len)+'">'+
						    '<div style="width:920px;margin-left:30px;">'+
						    '<table class="table" id="chengyaoyp" style="table-layout:fixed;">' +
						    '<thead> <tr><th style="width:250px">药品名称</th><th style="width:54px">组号</th> <th style="width:120px">用法</th><th style="width:138px">用药频率</th><th style="width:100px">每次剂量</th><th style="width:100px">开药量</th><th style="width:100px"></th><th style="width:25px"></th></tr></thead>'+
						    ' <tbody>';
							$(data).each(function(){
								var danjia = this.danjia;
								if(danjia==null) {
									danjia = 0;
								}
								var shuliang = this.kaiyaoliang;
								var jine = parseFloat(roundUtil(parseFloat(danjia), 8));
								var zuhao = this.zuhao;
								if(zuhao==0) {
									zuhao = '';
								}
								kelong += '<tr><td class="dropdown-search-li"><input type="text" class="wm-medicine-name cgmdc-input1 dropdown-toggle yaopinmc" data-rule="药品名称:length(1~100)" data-target="#msg_holder" name="yaopinmc" value="'+this.yaopinmc+'" onkeyup="getYaopin(this,2)" onblur="yaowuxk(this)" autocomplete="off">';
								if(this.zhensuoypid==null){
					         		kelong +='<div class="g-wmfinp-warning" style="display:block" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="该药品不在您的诊所库存中"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>';
					         	}
								kelong +='<div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
					         	'<div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
								'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'"><ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
						        '<td><input type="text" value="'+zuhao+'" class="wm-group dropdown-toggle cgmdc-input2 "data-rule="组号:integer[+];range[~99]" data-target="#msg_holder"  name="zuhao" autocomplete="off"><ul class="dropdown-menu cgmz-jcts"style="width: 52px;" role="menu"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul></td>'+
						        '<input type="hidden"  style="display:none;" name="zhensuoypid" value="'+this.zhensuoypid+'">'+
						        '<input type="hidden"  style="display:none;" name="pingtaiypid" value="'+this.pingtaiypid+'">'+
						        '<input type="hidden"  style="display:none;" name="ptuuid" value="'+this.ptuuid+'">'+
						         '<td class="dropdown-search-li"><input type="text" value="'+this.yongfa+'" class="input-sm  cgmdc-input3 dropdown-toggle yongfa" style="width:100%" name="yongfa" data-rule="用法:length(1~64)" data-target="#msg_holder" onfocus="getYongfazd(this)" onkeyup="getYongfazd(this)" autocomplete="off"><ul class="dropdown-menu li-width f-input-li yongfaul"   style="display:none" role="menu"></ul></td>'+
						         '<td class="dropdown-search-li"><input value="'+this.yongyaopl+'" class="wm-rate dropdown-toggle yongyypl cgmdc-input4" data-rule="用药频率:length(1~64)" data-target="#msg_holder" name="yongyaopl" onfocus="getZDYongyaoplBymc(this)" onkeyup="getZDYongyaoplBymc(this)" autocomplete="off"><ul class="dropdown-menu li-width f-input-li yongyyaoplul"  style="display:none" role="menu"></ul></td>'+
						         '<td class="wm-dosage-father dropdown-search-li">';
									if(this.dancijldw != "适量"){
										kelong +='<input type="text" value="'+this.dancijl+'" class="wm-dosage cgmdc-input51" name="dancijl" data-rule="单次剂量:range[0~];length(~8)" data-target="#msg_holder" autocomplete="off"> ';
									}else{
										kelong +='<input type="text" class="wm-dosage cgmdc-input51" name="dancijl" readOnly="readOnly" autocomplete="off"> ';
									};
									kelong +='<input value="'+this.dancijldw+'" class="wm-dosage dropdown-toggle cgmdc-input52" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="dancijldw" autocomplete="off">'+
						          	'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
						          	'<li>片</li>'+
			                 		'<li>粒</li>'+
			                 		'<li>支</li>'+
			                 		'<li>袋</li>'+
			                 		'<li>丸</li>'+
			                 		'<li>枚</li>'+
			                 		'<li>瓶</li>'+
			                 		'<li>滴</li>'+
			                 		'<li>克</li>'+
			                 		'<li>g</li>'+
			                 		'<li>ml</li>'+
			            	 		'<li class="wushuju" style="padding-left:0;text-align:center;">适量</li>'+
									   '</ul>'+	
						         '</td>'+
						         '<td class="wm-dosage-father wm-dosage-father2 dropdown-search-li">'+
						          	'<input  value="'+this.kaiyaoliang+'" type="text" class="wm-number cgmdc-input61" name="kaiyaoliang" data-target="#msg_holder" onkeyup="jisuanypje(this)" autocomplete="off"> ';
									if(this.zhensuoypid != null){
						          		if(this.chailingbz == 0||this.chailingbz == null){
						          			kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" readonly="readonly" name="kaiyaodw" style="background-color:#efefef;" autocomplete="off">'+
								          	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu">'+
											   '</ul></td>';
						          		}else{
						          			kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" readonly="readonly" name="kaiyaodw" autocomplete="off">'+
								          	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu"><li>'+this.chailingdw+'</li><li>'+this.baozhuangdw+'</li>'+
											   '</ul></td>';
						          		}
						          		
						          	}else{
						          		kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="kaiyaodw" autocomplete="off">'+
							          	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu">'+
							          	'<li>盒</li>'+
				                 		'<li>瓶</li>'+
				                 		'<li>支</li>'+
				                 		'<li>袋</li>'+
				                 		'<li>丸</li>'+
				                 		'<li>片</li>'+
				                 		'<li>粒</li>'+
				                 		'<li>板</li>'+
				                 		'<li>克</li>'+
				                 		'<li>g</li>'+
										   '</ul></td>';
						          	}
			                 	  kelong +=' <td class="jine" >';
						        if(this.zhensuoypid!=null) {
						        	kelong +='<input value="'+jine+'" data-rule="金额:range[0~];length(~10)" type="text" data-target="#msg_holder"  name="jine" readOnly="true" class="input-jine cgmdc-input7" autocomplete="off">';
						        }else{
						        	kelong +='<input value="'+jine+'"  type="text" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" class="input-jine inp-select cgmdc-input3" autocomplete="off">';
						        }
						        kelong +=' 元  </td>' +
								'<input type="hidden" name="danjia" value="'+danjia+'">'+
								'<input type="hidden" name="chailingsl" value="'+this.chailingsl+'">'+
								'<input type="hidden" name="baozhuangdw" value="'+this.baozhuangdw+'">'+
								'<input type="hidden" name="shengchancj" value="'+this.shengchancj+'">'+
								'<input type="hidden" name="baozhuanggg" value="'+this.baozhuanggg+'">'+
								'<input type="hidden" name="gongyingshang" value="'+this.gongyingshang+'">'+
								'<input type="hidden" name="kucunsl" value="'+this.kucunsl+'">'+
								'<input type="hidden" name="jixing" value="'+this.jixing+'">'+
						        '<td> <img class="pointer2" src="'+path+'../../image/shanc.png" alt=""></td>'+
						        '</tr>';
							});          
							
							kelong +='<tr><td class="dropdown-search-li"><input type="text" class="wm-medicine-name cgmdc-input1 dropdown-toggle yaopinmc" autocomplete="off" data-rule="药品名称:length(1~100)" data-target="#msg_holder" name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,2)"><input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'"><div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
						    '<td class="dropdown-search-li"><input type="text" class="wm-group dropdown-toggle" cgmdc-input2 autocomplete="off" data-rule="组号:integer[+];range[~99]" data-target="#msg_holder"  name="zuhao"><ul class="dropdown-menu cgmz-jcts"style="width: 52px;" role="menu"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul></td>'+
						    '<input type="hidden"  style="display:none;" name="zhensuoypid" >'+
						    '<input type="hidden"  style="display:none;" name="pingtaiypid" >'+
						    '<input type="hidden"  style="display:none;" name="ptuuid" >'+
						     '<td class="dropdown-search-li"><input type="text" class="input-sm  cgmdc-input3 dropdown-toggle yongfa" autocomplete="off" style="width:100%" id="chengy-yf'+(len+1)+'" name="yongfa" data-rule="成药用法:length(1~64)" data-target="#msg_holder"><ul class="dropdown-menu li-width f-input-li yongfaul"   style="display:none" role="menu"></ul></td>'+
						     '<td class="dropdown-search-li"><input class="wm-rate dropdown-toggle yongyypl cgmdc-input4" autocomplete="off" id="chengy-yongypl'+(len+1)+'" data-rule="用药频率:length(1~64)" data-target="#msg_holder" name="yongyaopl" onfocus="getZDYongyaoplBymc(this)" onkeyup="getZDYongyaoplBymc(this)"><ul class="dropdown-menu li-width f-input-li yongyyaoplul"  style="display:none" role="menu"></ul></td>'+
						     '<td class="wm-dosage-father dropdown-search-li">'+
						      	'<input type="text" class="wm-dosage cgmdc-input51" autocomplete="off" name="dancijl" data-rule="单次剂量:range[0~];length(~8)" data-target="#msg_holder"> ' + 
						      	'<input class="wm-dosage dropdown-toggle cgmdc-input52" autocomplete="off" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="dancijldw">'+
						      	'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
						      	'<li>片</li>'+
						 		'<li>粒</li>'+
						 		'<li>支</li>'+
						 		'<li>袋</li>'+
						 		'<li>丸</li>'+
						 		'<li>枚</li>'+
						 		'<li>瓶</li>'+
						 		'<li>滴</li>'+
						 		'<li>克</li>'+
					     		'<li>g</li>'+
						 		'<li>ml</li>'+
						 		'<li class="wushuju" style="padding-left:0;text-align:center;">适量</li>'+
								   '</ul>'+	
						     '</td>'+
						     '<td class="wm-dosage-father wm-dosage-father2 dropdown-search-li">'+
						      	'<input type="text" class="wm-number cgmdc-input61" autocomplete="off" name="kaiyaoliang"  data-target="#msg_holder" onkeyup="jisuanypje(this)"> ' + 
						      	'<input class="wm-dosage dropdown-toggle cgmdc-input62" autocomplete="off" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="kaiyaodw">'+
						      	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu">'+
						      	'<li>盒</li>'+
						 		'<li>瓶</li>'+
						 		'<li>支</li>'+
						 		'<li>袋</li>'+
						 		'<li>丸</li>'+
						 		'<li>片</li>'+
						 		'<li>粒</li>'+
						 		'<li>板</li>'+
						 		'<li>克</li>'+
					     		'<li>g</li>'+
							    '</ul></td>'+
						    ' <td class="jine"><input  data-rule="金额:range[0~];length(~10)" autocomplete="off" data-target="#msg_holder" type="text" name="jine" class="input-jine cgmdc-input7 inp-select"> 元</td>'+
							'<input type="hidden" name="danjia" value="0">'+
							'<input type="hidden" name="chailingsl">'+
							'<input type="hidden" name="baozhuangdw">'+
							'<input type="hidden" name="shengchancj" >'+
							'<input type="hidden" name="baozhuanggg" >'+
							'<input type="hidden" name="gongyingshang" >'+
							'<input type="hidden" name="kucunsl">'+
							'<input type="hidden" name="jixing">'+
						    '<td> <div class="g-mz-delete pointer2" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'+path+'../../image/shanc.png" alt=""></div></td>'+
						    '</tr>';
							kelong +='</tbody>'+
						     '</table>'+
							 '</div></div>';
							$(".western-medicine:last").after(kelong);//添加成药模板			
							$(".western-medicine:last .yaopinmc").focus();	
							$('[name="kaiyaoliang"]:not(:last)').trigger('keyup');	
							}
						}
					});
				}else {
					$.ajax({
					    type:"POST",
					    url:'./changguimz/getExCaoyaoyp',
					    data:{id:id},
					    success:function(data){
							if(data!="") {
								var len=$(".chinese-medicine").length;
								var kelong='<div class="chinese-medicine g-m-chinese" id="chinese-medicine">'+
						          '<div class="chinese-head">草药处方'+(len)+'<span class="medicine-delete"> 删除处方</span></div>'+
						          '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
						          '<input type="hidden" style="display:none;" name="mingcheng" value="'+"草药处方"+(len)+'">'+
						          '<div class="medicine-herb">'+
						              '<div class="medicine-item">'+
							              	 	'<label class="l-ibt-label"><span class="glyph-star">*</span>剂数：</label>'+
							                  '<input id="tieshu" value="'+data[0].tieshu+'" type="text" class="m-inform" data-rule="剂数:required;range[1~];length(~2)" value="1" data-target="#msg_holder"  name="tieshu" onkeyup="jiasuancaoyao(this)" autocomplete="off"> 剂'+
							         '</div>' +
							          '<div class="medicine-item">'+
							              '<label><span class="glyph-star" style="vertical-align: middle;">*</span>每日剂数：'+
							                  '<input value="'+data[0].meirijl+'" type="number" class="m-inform" data-rule="每日剂数:required;range[0~];length(~2)" data-target="#msg_holder" name="meirijl" autocomplete="off"> 剂'+
							              '</label>'+
							         '</div>'+
							         '<div class="medicine-item dropdown-search-li">'    +
							             '<label class="l-heart-rhythm">' +
							               '<span><span class="glyph-star" style="vertical-align: middle;">*</span>用药频率：</span>' +
							              '</label>'+
						                  '<input  value="'+data[0].yongyaopl+'" class="m-inform yongyypl dropdown-toggle" name="yongyaopl" data-rule="用药频率:required;length(1~64)" data-target="#msg_holder" onfocus="getZDYongyaoplBymc(this)"  onkeyup="getZDYongyaoplBymc(this)" autocomplete="off">' +
						                  '<ul class="dropdown-menu li-width f-input-li yongyyaoplul" id="yongfaul"  style="display:none; margin-bottom:0;" role="menu">'+
									  	 '</ul>'+
							        '</div>'      + 
						             '<div class="medicine-item mi-usage dropdown-search-li"> '+
						               '<span class="mitem-usage"><span class="glyph-star">*</span>用法：</span>' +
						                 '<input value="'+data[0].yongfa+'" class="m-inform dropdown-toggle yongfa" name="yongfa" data-rule="用法:required;length(1~64)"  data-target="#msg_holder" onfocus="getYongfazd(this)"  onkeyup="getYongfazd(this)" autocomplete="off"> ' +
						                 '<ul class="dropdown-menu li-width f-input-li yongfaul" id="yongfaul" style="display:none"  role="menu">' +
									  	 '</ul>'+
						            '</div>'+
						           '<div class="medicine-item medicine-item2x">' +
						               '<label for="input-else" class="l-ielse" style="margin-left: 2px;">服用要求：</label>' +
						                ' <input type="text" value="'+data[0].fuyongyq+'" class="m-inform" data-rule="用药频率:length(1~128)" data-target="#msg_holder" id="input-else" name="fuyongyq" autocomplete="off">' +
						           '</div>'+
						     '</div>' +
						     '<div style="margin:0 auto;">'+
						     ' <table class="table" id="caoyaoyp" style="table-layout:fixed;">'+
						        '<tbody>' ;
								var lengthNew = $(data).length
								$(data).each(function(i,e){
									var danjia = this.danjia;
									if(danjia==null) {
										danjia = 0;
									}
									var beizhu = this.beizhu;
									if(beizhu == null){
										beizhu = '';
									}

									var shuliang = this.danjiliang;
									var jine = parseFloat(roundUtil(parseFloat(danjia), 8));
									kelong +='<tr>'+
						        	'<td class="zymb-number">饮片'+(i+1)+'：</td>'+
						         	'<td class="zymb-td2 dropdown-search-li"><input type="text" value="'+this.yaopinmc+'" style="text-align:left;" class="wm-medicine-name dropdown-toggle yaopinmc cgmdc-input1" data-rule="药品名称:length(1~100)" data-target="#msg_holder" name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,1)" autocomplete="off">';
						         	if(this.zhensuoypid==null){
						         		kelong +='<div class="g-wmfinp-warning" style="display:block" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="该药品不在您的诊所库存中"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>';
						         	}
						         	kelong +='<div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
						         	'<div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
									'<ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
						         	'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
						            '<td class="zymb-td3"><input value="'+this.danjiliang+'" type="text" placeholder="数量" style="text-align:center;" class="wm-solo-dosage cgmdc-input2" name="danjiliang" data-target="#msg_holder"  onkeyup="jisuanypje(this)" autocomplete="off">';
						            if(this.chailingbz == null){
						            		kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei"  style="margin-left:5px;text-align: center;">'+
								            		'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu">'+
													'<li>盒</li>'+
											   		'<li>瓶</li>'+
											   		'<li>支</li>'+
											   		'<li>袋</li>'+
											   		'<li>丸</li>'+
											   		'<li>片</li>'+
											   		'<li>粒</li>'+
											   		'<li>板</li>'+
											   		'<li>克</li>'+
											   		'<li>个</li>'+
											   		'</ul>';
						            }else if(this.chailingbz == 0){
											kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei" readonly="readonly" style="margin-left:5px;text-align: center;">';
						            }else  if(this.chailingbz == 1){
						            	kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei"  readonly="readonly" style="margin-left:5px;text-align: center;background-color:#fff;">'+
												'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu"><li>'+this.baozhuangdw+'</li>'+
												'<li>'+this.chailingdw+'</li></ul>';
						            }else{
						            	kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle " data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei" style="margin-left:5px;text-align: center;background-color:#fff;">'+
										'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu"><li>'+this.baozhuangdw+'</li>'+
										'<li>盒</li>'+
								   		'<li>瓶</li>'+
								   		'<li>支</li>'+
								   		'<li>袋</li>'+
								   		'<li>丸</li>'+
								   		'<li>片</li>'+
								   		'<li>粒</li>'+
								   		'<li>板</li>'+
								   		'<li>克</li>'+
								   		'<li>个</li>'+
								   		'</ul>';
						            }
						         	kelong +='</td>'+
						            '<td class="zymb-td4">'+
						            '<input class="dropdown-toggle" type="text" placeholder="备注"  data-rule="备注:length(1~100)" data-target="#msg_holder" name="beizhu" value="'+beizhu+'">'+
						            	'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
							            	'<li>已取</li>'+
											'<li>口服</li>'+
											'<li>泡服</li>'+
											'<li>外用</li>'+
											'<li>先煎</li>'+
											'<li>后下</li>'+
											'<li>水煎</li>'+
											'<li>包煎</li>'+
											'<li>打碎</li>'+
											'<li>另包</li>'+
											'<li>吞服</li>'+
											'<li>另煎</li>'+
											'<li>烊化</li>'+
											'<li>冲服</li>'+
											'<li>内服</li>'+
											'<li>入丸</li>'+
										'</ul>'+
									'</td>'+
						            '<input type="hidden"  style="display:none;" name="zhensuoypid" value="'+this.zhensuoypid+'">'+
							        '<input type="hidden"  style="display:none;" name="pingtaiypid" value="'+this.pingtaiypid+'">'+
							        '<input type="hidden"  style="display:none;" name="ptuuid" value="'+this.ptuuid+'">'+
							        '<input type="hidden" name="kucunsl" value="'+this.kucunsl+'">'+
							        '<input type="hidden" name="chailingsl" value="'+this.chailingsl+'">'+
							        '<input type="hidden" name="baozhuangdw" value="'+this.baozhuangdw+'">'+
									'<input type="hidden" name="shengchancj" value="'+this.shengchancj+'">'+
									'<input type="hidden" name="baozhuanggg" value="'+this.baozhuanggg+'">'+
									'<input type="hidden" name="gongyingshang" value="'+this.gongyingshang+'">'+
							        ' <td class="jine" >';
							        if(this.zhensuoypid!=null) {
							        	kelong +='<input value="'+jine+'"  type="text" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" readOnly="true" class="input-jine cgmdc-input3" autocomplete="off">';
							        }else{
							        	kelong +='<input data-toggle="popover" data-placement="bottom" data-content="" value="'+jine+'"  type="text" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" class="input-jine cgmdc-input3 inp-select" autocomplete="off">';
							        }
									kelong +='元</td>'+
									'<input type="hidden" name="danjia" value="'+danjia+'">'+
						            '<td><img  class="pointer3" src="'+path+'../image/shanc.png" alt=""></td>'+
						            '</tr>';
								});   
								kelong += '<tr>'+
								'<td class="zymb-number">饮片'+(lengthNew+1)+'：</td>'+
							 	'<td class="zymb-td2 dropdown-search-li"><input type="text" class="wm-medicine-name dropdown-toggle yaopinmc cgmdc-input1" style="text-align: left;" autocomplete="off" data-rule="药品名称:length(1~100)" data-target="#msg_holder"  name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,1)"><div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
							 	'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
							    '<td class="zymb-td3"><input type="text" placeholder="数量" class="wm-solo-dosage cgmdc-input2" autocomplete="off" name="danjiliang"  data-target="#msg_holder"  onkeyup="jisuanypje(this)">'+
							    '<input class="wm-dosage dropdown-toggle cgmdc-input62" placeholder="单位" autocomplete="off" name="danwei" style="margin-left:5px;text-align: center;">'+
						      	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu">'+
							      	'<li>盒</li>'+
							   		'<li>瓶</li>'+
							   		'<li>支</li>'+
							   		'<li>袋</li>'+
							   		'<li>丸</li>'+
							   		'<li>片</li>'+
							   		'<li>粒</li>'+
							   		'<li>板</li>'+
							   		'<li>克</li>'+
							   		'<li>个</li>'+
						   		'</ul></td>'+
							    '<td class="zymb-td4">'+
							    '<input class="dropdown-toggle" type="text" placeholder="备注"  data-rule="备注:length(1~100)" data-target="#msg_holder" name="beizhu">'+
									'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
										'<li>已取</li>'+
										'<li>口服</li>'+
										'<li>泡服</li>'+
										'<li>外用</li>'+
										'<li>先煎</li>'+
										'<li>后下</li>'+
										'<li>水煎</li>'+
										'<li>包煎</li>'+
										'<li>打碎</li>'+
										'<li>另包</li>'+
										'<li>吞服</li>'+
										'<li>另煎</li>'+
										'<li>烊化</li>'+
										'<li>冲服</li>'+
										'<li>内服</li>'+
										'<li>入丸</li>'+
									'</ul>'+
								'</td>'+
							    '<input type="hidden"  style="display:none;" name="zhensuoypid" >'+
							    '<input type="hidden"  style="display:none;" name="pingtaiypid" >'+
							    '<input type="hidden"  style="display:none;" name="ptuuid" >'+
							    ' <td class="jine"><input  type="text" data-toggle="popover" data-placement="bottom" data-content="" data-rule="金额:range[0~];length(~10)" autocomplete="off" data-target="#msg_holder" name="jine" class="input-jine cgmdc-input3 inp-select"> 元</td>'+
								'<input type="hidden" name="danjia" value="0">'+
								'<input type="hidden" name="kucunsl">'+
								'<input type="hidden" name="chailingsl">'+
								'<input type="hidden" name="baozhuangdw">'+
								'<input type="hidden" name="shengchancj">'+
								'<input type="hidden" name="baozhuanggg">'+
								'<input type="hidden" name="gongyingshang">'+
							    '<td><div class="g-mz-delete pointer3" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'+path+'../image/shanc.png" alt=""></div></td>'+
							    '</tr>';  
								kelong += '</tbody>'+
									      '</table>' +
									      '</div>'+
											'<div class="clearfix" id="heji">'+
											'<span style="float:right;margin:0 30px 15px 0;">处方总金额：<span class="chufangzje">0.00元</span></span>'+
											'<span style="float:right;margin:0 30px 15px 0;">单剂总金额：<span class="danjizongje">0.00元</span></span>'+
											'<span style="float:right;margin:0 30px 15px 0;" >共计<span class="yaopingsl">0</span>味药</span>'+
											'</div>'+
											'</div>';
								$(".chinese-medicine:last").after(kelong);//添加成药模板
								$('[name="tieshu"]').trigger('keyup');
								$('[name="danjiliang"]:not(:last)').trigger('keyup');
								$(".chinese-medicine:last .yaopinmc").focus();
								$("input:text").attr("autocomplete","off");
								}
							}
						});
				}
		});	
		$("#mymodal-data").modal('hide');
	});
	
	function getZsYaopinje(zhensuoypid) {
		$.ajax({
		    type:"POST",
		    url:'./yizhudy/getYizhu',
		    data:sendData,
		    success:function(data){
				if(data!="") {
					$('#changyongyz').html("");
					$(data).each(function(i,e) {
						index = i+1;
						var content='<tr>';
						content+='<tr class="cgmz-tr-radio">';
						content+='<td class="col-sm-1"><input type="checkbox" name="nixie" >'+index+'</label></td>';
						content+='<td class="col-sm-3 neirong">'+this.neirong+'</td>';
						content+='</tr>'
					
						$('#changyongyz').append(content);
					});
				}
				$("#mymodal-yizhu").modal();
			}
		});
	}
	
	//引用常用医嘱
	$('#btnChangyongyz').click(function() {
		yizhulx = null;
		getChangyongyz(yizhulx);
	});
	
	function getChangyongyz(yizhulx){
		$.ajax({
		    type:"POST",
		    url:'./yizhudy/getYizhu',
		    data:{yizhulx:yizhulx},
		    success:function(data){
		    	$('#changyongyz').html("");
				if(data!="") {
					$(data).each(function(i,e) {
						index = i+1;
						var content='<tr class="cgmz-tr-radio">';
						var leixing = '诊所';
						if(this.iszs == 0) {
							leixing = '诊所';
						}else{
							leixing = '平台';
						}
						content+='<td class="col-sm-3 neirong"  style="text-align:left;"><input type="checkbox" name="nixie1" id="cyyz'+index+'" style="display:none";><label class="cymb-check1 oncymb-check1" for="cyyz'+index+'"><span id="yizhunr">'+this.neirong+'</span><span style="float:right; margin-right:40px;line-height: 40px;">'+leixing+'</span></label></td>';
						content+='</tr>';
						$('#changyongyz').append(content);
					});
					$("#mymodal-yizhu").modal();
				}else{
					if(yizhulx==null) {
						notifyInfo("您还没维护医嘱");
					}else if(yizhulx==1) {
						notifyInfo("您还没维护诊所医嘱");
					}
				}
				
			}
		});
		$("#mymodal-yizhu .button-box ul li").removeClass("xuanzhong")
		$('#btnQuanbu-yz').addClass("xuanzhong");
	}
	
	var yizhulx = null;
	//常用处方点击条件
	$('#btnQuanbu-yz').click(function(){
		yizhulx = null;
		getChangyongyz(yizhulx);
		$("#mymodal-yizhu .button-box ul li").removeClass("xuanzhong")
		$(this).addClass("xuanzhong");
	});
	$('#btnZhensuo').click(function(){
		yizhulx = 1;
		getChangyongyz(yizhulx);
		$("#mymodal-yizhu .button-box ul li").removeClass("xuanzhong")
		$(this).addClass("xuanzhong");
	});
	$('#btnPingtai').click(function(){
		yizhulx = 0;
		getChangyongyz(yizhulx);
		$("#mymodal-yizhu .button-box ul li").removeClass("xuanzhong")
		$(this).addClass("xuanzhong");
	});
	
	//点击常用医嘱保存
	$(document).on('click','#btnchangyongyz',function(){
		var neirong = $('#div-yizhu').html();
		if(neirong!="") {
			neirong = neirong+',';
		}
		$('input:checkbox[name=nixie1]:checked').each(function(i,e){
			if(i==0) {
	    		neirong += $(this).parent().parent().find('#yizhunr').text();
	    	}else{
	    		neirong += ',' + $(this).parent().parent().find('#yizhunr').text();
	    	}
		});
		$('#div-yizhu').text(neirong);
		$('#cgmz-l3yz').val(neirong);
		$("#mymodal-yizhu").modal('hide');
		if(neirong.length>200){
			var text =neirong.substring(0,199);
			$("#div-yizhu").html(text);
			$('#cgmz-l3yz').val(text);
			notifyWarning('医嘱可输入最大长度为200个字符');
			$("#div-yizhu").focus();
		}
	});

	//点击进入患者详情信息
	$('.g-l-1r-top').click(function() {
		//通过id得到患者信息
		$.ajax({
		    type:"get",
		    //获取json文件路径
		    url:"./huanzhe/getHuanzheById",
		    //传送数据
		    data:{id:huanzheid},
		    async:false,
		    //请求成功完成后要执行的方法
		    success: function(data){
		    	//显示详情信息
		    	if(data!="") {
		    		var huanzhexx = data.huanzhexx;
		    		$('#xingming').text(huanzhexx.xingming);
		    		if(huanzhexx.xingbie != null){
		    			if(huanzhexx.xingbie==1) {
			    			$('#xingbie').text('男');
			    		}else if(huanzhexx.xingbie==2){
			    			$('#xingbie').text('女');
			    		}
		    		}else {
		    			$('#xingbie').css("display","none");
		    		}
		    		$('#nianling').text(huanzhexx.nianling);
		    		if(huanzhexx.nianling != null){
		    			if(huanzhexx.nianlingdw=='岁') {
			    			$("#f-le-nianlingdw").text('岁');
			    		}else if(huanzhexx.nianlingdw=='月'){
			    			$("#f-le-nianlingdw").text('月');
			    			
						}
		    		}else {
		    			$("#hz-nianlingdw").hide();
		    		}
		    		$('#shoujihm').text(huanzhexx.shoujihm);
		    		$('#shenfenzhm').text(huanzhexx.shenfenzhm);
		    		$('#jinjilxr').html(huanzhexx.jinjilxr);
		    		$('#jinjilxdh').html(huanzhexx.jinjilxdh);
		    		$('#xiangxizz').html(huanzhexx.xiangxizz);
		    		$('#guominshi').html(common_util.nullToEmpty(huanzhexx.guominshi));
		    		$('#div-guominshi').html(common_util.nullToEmpty(huanzhexx.guominshi));
		    		$('#beizhu').html(huanzhexx.beizhu);
		    		if(huanzhexx.shengfen != ''&&huanzhexx.shengfen != null){
		    			$("#hz-dizhi-sf").html(huanzhexx.shengfen+'/');
		    		}else {
		    			$("#hz-dizhi-sf").html('');
		    		}
		    		if(huanzhexx.chengshi != ''&&huanzhexx.chengshi != null){
		    			$("#hz-dizhi-cs").html(huanzhexx.chengshi+'/');
		    		}else {
		    			$("#hz-dizhi-cs").html('');
		    		}
		    		if(huanzhexx.quxian != ''&&huanzhexx.quxian != null){
		    			$("#hz-dizhi-qx").html(huanzhexx.quxian);
		    		}else {
		    			$("#hz-dizhi-qx").html('');
		    		}
		    		$("#fenzuid").html(huanzhexx.fenzuid);
		    		$("#id").html(huanzhexx.id);
		    		//显示关联人信息
		    		if(data.guanlianhzs!="") {
		    			$(data.guanlianhzs).each(function(){
		    				if(huanzhexx.id!=this.id) {
		    					var shoujihm = this.shoujihm;
								if(shoujihm==null) {
									shoujihm = "";
								}
			    				var str = '<tr value="'+this.id+'" class="medicine-item-tr"><td  class="hzn-name"><label class=" mi-table-label2" ></label></td>'+
					               '<td width="100%" class="hzn-name-td2"><label class=" mi-table-label2" >'+this.xingming+'&nbsp;&nbsp;&nbsp;'+shoujihm+'</label><img class="pointer2" src="'+path+'/image/shanc.png" alt="">'+
					               '<ul id="dropdownli" class="dropdown-menu li-width f-input-li"  style="display:none;" role="menu"></ul>'+
					               '</td>'+
					               '<td class="hzn-name"><label class="mi-table-label2" ></label></td>'+
					               '<td class="hzn-name-td4">'+
					               '</td>'+
				                '</tr>'
			    				$("#tbguanlr").append(str);
			    				$(".pointer2").css("display","none");
			    				var ids = $('#guanlianrids').val();
								$('#guanlianrids').val(ids+","+this.id);
								$("#fenzuid").val(this.fenzuid);
		    				}
		    			});
		    		}
		    	}
		    }
		});
		$("#mymodal-xxxx").modal();
	});

	var jiuzhenjlid2;
	//点击进入历史就诊
	$('#hz-jiuzjl').click(function() {
		$('#jiuzhenjlnew').modal();
		showHuanzhelsjz();
		showJiuZhenxq(jiuzhenjlid2);
	});
	$('#btnYinyong').click(function(){
		ignoreInput(yinyongjzjlid,0,3);//此时是引用，不能禁止输入 微诊疗为1 常规门诊为3
		$("#jiuzhenjlnew").modal('hide');
	});
	
		
	//计算总金额
	$('#formSave').click(function(){
		jisuanYmje()
	}).keyup(function(event){
		keyCode = event.which;
		jisuanYmje()
	});
	$(document).on("click","#tbjinrmz tr",function(){
		var jiuz_id = $(this).attr('id');
		var jiuz_leixing = $(this).attr('leixing');
		var jiuz_yewurk = $(this).attr('yewurk');
		if(A>0){
		$("#cgmz-out").modal();
		}else{
			ignoreInput(jiuz_id,jiuz_leixing,jiuz_yewurk);
			A=0;
		}
		$("#cgmz-out-queding").click(function(){
			$("#cgmz-out").modal("hide");
			ignoreInput(jiuz_id,jiuz_leixing,jiuz_yewurk);
			A=0;
		});
	});
	var jiuzhenjlid = null;
	var zhuangtai;
	//今日门诊点击一行
	function ignoreInput(jiuzhenid,isYinyong,yewurk){
		if(isYinyong!=0)
			getTuxiangzl(keyArry, jiuzhenid, ".img-hasimginof", 1);
		jiuzhenjlid = jiuzhenid;
		if(yewurk==1) {//跳转到微诊疗页面
			window.location.href=  path+'/jump/toWeizl?type=1&jiuzhenid='+jiuzhenid;
		}else if(yewurk==3) {
			$.ajax({
			    type:"get",
			    //获取json文件路径
			    url:"./changguimz/getById",
			    //传送数据
			    data:{id:jiuzhenid},
			    async:false,
			    //请求成功完成后要执行的方法
			    success: function(data){
			    	//显示详情信息
			    	if(data!="" && null != data) {
			    		if (null !=data.guahaoxxid) {
			    			$('#higuahaoid').val(data.guahaoxxid);
			    		}
			    		/****        患者部分       ****/
			    		var huanzhexx = data.huanzhexx;
			    		
			    		huanzheid = huanzhexx.id;
			    		$(".g-l-1right").css('display','block');
			    		$('#huanzheid').val(huanzhexx.id);
			    		$('#inputname').val(huanzhexx.xingming);
			    		$('#inputage').val(huanzhexx.nianling);
			    		$('#inputphone').val(huanzhexx.shoujihm);
			    		$('#g-allergy').val(huanzhexx.guominshi);
			    		$('#div-allergy').html(common_util.nullToEmpty(huanzhexx.guominshi));
			    		
			    		if(huanzhexx.xingbie==1) {
			    			$('#nan').attr('checked','checked');
			    			$('#work-label').attr('class','radio-label cgbj-input on');
			    			$('#stop-label').attr('class','radio-label');
			    		}else if(huanzhexx.xingbie==2){
			    			$('#nv').attr('checked','checked');
			    			$('#stop-label').attr('class','radio-label  on');
			    			$('#work-label').attr('class','radio-label cgbj-input');
			    		}
			    		
			    		if(huanzhexx.nianlingdw=='岁') {
			    			$("#f-le-nianlingdw").text('岁')
			    		}else {
			    			$("#f-le-nianlingdw").text('月')
			    		}
			    		
			    		/****        病例信息部分部分       ****/
			    		$('#first-info').val(data.zsJiuzhenjl.zhushu);
			    		$('#div-zhushu').html(data.zsJiuzhenjl.zhushu);
			    		$('#input-disease').val(data.zsJiuzhenjl.xianbingshi);
			    		$('#div-disease').html(data.zsJiuzhenjl.xianbingshi);
			    		$('#input-history').val(data.zsJiuzhenjl.jiwangshi);
			    		$('#div-history').html(data.zsJiuzhenjl.jiwangshi);
			    		$('#input-body-temperature').val(data.zsJiuzhenjl.tiwen);
			    		$('#input-body-weight').val(data.zsJiuzhenjl.tizhong);
			    		$('#input-heart-pressure').val(data.zsJiuzhenjl.shousuoya);
			    		$('#input-heart-pressure2').val(data.zsJiuzhenjl.shuzhangya);
			    		$('#input-heart-rate').val(data.zsJiuzhenjl.xinlv);
			    		$('#cgmz-l3yz').val(data.zsJiuzhenjl.yizhu);
			    		$('#div-yizhu').html(data.zsJiuzhenjl.yizhu);
			    		$('#input-examine').val(data.zsJiuzhenjl.qitatz);
			    		$('#div-examine').html(data.zsJiuzhenjl.qitatz);
			    		var xinlvzb = data.zsJiuzhenjl.xinlvzb;
			    		if(xinlvzb==1) {
			    			$('#f-le-fenlei2').text("心律正常");
			    		}else if(xinlvzb==0) {
			    			$('#f-le-fenlei2').text("心律不齐");
			    		}
			    		$('#input-examine').val(data.zsJiuzhenjl.qitatz);
			    		
			    		//诊断
			    		var zsJiuzhenzds = data.zsJiuzhenzds;
			    		var zdStr = '';
			    		$(zsJiuzhenzds).each(function(){
			    			var iszs = '';
			    			var index = '';
			    			if(!!this.zhensuojbid){
			    				iszs = '1';
			    				index = this.zhensuojbid+'';
			    			}else{
			    				iszs = '0';
			    				index = this.pingtaijbid+'';
			    			}
			    			var icd10 = this.icd10;
			    			if(!!icd10 && icd10 != 'undefined'){
			    				zdStr += '<span iszs='+iszs+' index='+index+' class="cgmz-l2zd-dropmain">'+this.jibingmc+'&nbsp;&nbsp;&nbsp;'+this.icd10+'<span class="cgmz-l2zd-dropimg"></span></span>';
			    			}else{
			    				zdStr += '<span iszs='+iszs+' index='+index+' class="cgmz-l2zd-dropmain">'+this.jibingmc+'<span class="cgmz-l2zd-dropimg"></span></span>';
			    			}
			    		});
			    		$('.cgmz-l2zd-dropdown').html("");
			    		$('.cgmz-l2zd-dropdown').append(zdStr);
			    		
			    		//是否寄存
			    		if(data.zsJiuzhenjl.jicunbz==1) {
			    			$('#cgmz-sfjc-input').attr('checked','checked');
			    			$("#c-check1").removeClass("on-check1").addClass("c-check2");
			    			$('.cgmz-check-toggle').css("display","inline")
			    			$('#hijicunbz').val(1);
			    			$('#jicunts').val(data.zsJiuzhenjl.jicunts);
			    		}else if(data.zsJiuzhenjl.jicunbz==0) {
			    			$('#cgmz-sfjc-input').attr('checked',false);
			    			$("#c-check1").removeClass("c-check2").addClass("on-check1");
			    			$('#hijicunbz').val(0);
			    		}
			    		
			    		/****        处方部分       ****/
			    		$(".western-medicine:not(:first)").remove();
			    		var exZsChengyaocfs = data.exZsChengyaocfs;
			    		if(exZsChengyaocfs!="") {
			    			$(exZsChengyaocfs).each(function(){
			    				var zsChengyaocf = this.zsChengyaocf;
			    				var kelong ="";
			    				var yaopins = this.exYaopins;
			    				var len=$(".western-medicine").length;
								 kelong= '<div class="western-medicine g-m-west">'+
							    '<div class="chinese-head">'+zsChengyaocf.mingcheng+'<span class="medicine-delete">删除处方</span></div>'+
							    '<input type="hidden" class="western-paixu">'+
							    '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+zsChengyaocf.paixu+'">'+
						        '<input type="hidden" style="display:none;" name="mingcheng" value="'+zsChengyaocf.mingcheng+'">'+
							    '<div style="width:920px;margin-left:30px;">'+
							    '<table class="table" id="chengyaoyp" style="table-layout:fixed;">' +
							    '<thead> <tr><th style="width:250px">药品名称</th><th style="width:54px">组号</th> <th style="width:120px">用法</th><th style="width:138px">用药频率</th><th style="width:100px">每次剂量</th><th style="width:100px">开药量</th><th style="width:100px"></th><th style="width:25px"></th></tr></thead>'+
							    '<tbody>';
								$(yaopins).each(function(){
										var danjia = this.danjia;
										if(danjia==null) {
											danjia = 0;
										}
										var shuliang = this.kaiyaoliang;
//										var jine = parseFloat(danjia);
//										console.log('chengyaoje'+jine)
//										jine = '￥'+jine.toFixed(2);
										var zuhao = this.zuhao;
										if(zuhao==null||zuhao==0) {
											zuhao = '';
										}
										if(this.dancijldw == "适量"){
											$("#ssdancijl").val('12');
										}else{
											$(".cgmdc-input51").attr('readOnly',false);
										}
										kelong += '<tr><td class="dropdown-search-li"><input type="text" class="wm-medicine-name cgmdc-input1 dropdown-toggle yaopinmc" data-rule="药品名称:length(1~100)" data-target="#msg_holder" name="yaopinmc" value="'+this.yaopinmc+'" onblur="yaowuxk(this)" onkeyup="getYaopin(this,2,event)" autocomplete="off"><input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
										'<div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
										'<ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
										'<td class="dropdown-search-li"><input type="text" value="'+zuhao+'" class="wm-group dropdown-toggle cgmdc-input2"  autocomplete="off" data-rule="组号:integer[+];range[~99]" data-target="#msg_holder"  name="zuhao"><ul class="dropdown-menu cgmz-jcts"style="width: 52px;" role="menu"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul></td>'+
								        '<input type="hidden"  style="display:none;" name="zhensuoypid" value="'+this.zhensuoypid+'">'+
								        '<input type="hidden"  style="display:none;" name="pingtaiypid" value="'+this.pingtaiypid+'">'+
								        '<input type="hidden"  style="display:none;" name="ptuuid" value="'+this.ptuuid+'">'+
								         '<td class="dropdown-search-li"><input type="text" value="'+this.yongfa+'" class="input-sm  cgmdc-input3 dropdown-toggle yongfa" style="width:100%" name="yongfa" data-rule="用法:length(1~64)" data-target="#msg_holder" onfocus="getYongfazd(this)" onkeyup="getYongfazd(this)" autocomplete="off"><ul class="dropdown-menu li-width f-input-li yongfaul"   style="display:none" role="menu"></ul></td>'+
								         '<td class="dropdown-search-li"><input value="'+this.yongyaopl+'" class="wm-rate dropdown-toggle yongyypl cgmdc-input4" data-rule="用药频率:length(1~64)" data-target="#msg_holder" name="yongyaopl" onfocus="getZDYongyaoplBymc(this)" onkeyup="getZDYongyaoplBymc(this)" autocomplete="off"><ul class="dropdown-menu li-width f-input-li yongyyaoplul"  style="display:none" role="menu"></ul></td>'+
								         '<td class="wm-dosage-father dropdown-search-li">';
										if(this.dancijldw != "适量"){
											kelong +='<input type="text" value="'+this.dancijl+'" class="wm-dosage cgmdc-input51" name="dancijl" data-rule="单次剂量:range[0~];length(~8)" data-target="#msg_holder" autocomplete="off"> ';
										}else{
											kelong +='<input type="text" class="wm-dosage cgmdc-input51" name="dancijl" readOnly="readOnly" data-rule="单次剂量:range[0~];length(~8)" data-target="#msg_holder" autocomplete="off"> ';
										};
								          	
										kelong +='<input value="'+this.dancijldw+'" class="wm-dosage dropdown-toggle cgmdc-input52" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="dancijldw" autocomplete="off">'+
								          	'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
									          	'<li>片</li>'+
						                 		'<li>粒</li>'+
						                 		'<li>支</li>'+
						                 		'<li>袋</li>'+
						                 		'<li>丸</li>'+
						                 		'<li>枚</li>'+
						                 		'<li>瓶</li>'+
						                 		'<li>滴</li>'+
						                 		'<li>克</li>'+
						                 		'<li>g</li>'+
						                 		'<li>ml</li>'+
						            	 		'<li class="wushuju" style="padding-left:0;text-align:center;">适量</li>'+
											'</ul>'+	
								         '</td>'+
								         '<td class="wm-dosage-father wm-dosage-father2 dropdown-search-li">'+
								          	'<input  value="'+this.kaiyaoliang+'" type="text" class="wm-number cgmdc-input61" name="kaiyaoliang" data-target="#msg_holder" onkeyup="jisuanypje(this)" autocomplete="off"> ';
								          	if(this.chailingbz == null){
								          		kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="kaiyaodw" autocomplete="off">'+
									          	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu">'+
									          	'<li>盒</li>'+
						                 		'<li>瓶</li>'+
						                 		'<li>支</li>'+
						                 		'<li>袋</li>'+
						                 		'<li>丸</li>'+
						                 		'<li>片</li>'+
						                 		'<li>粒</li>'+
						                 		'<li>板</li>'+
						                 		'<li>克</li>'+
						                 		'<li>g</li>'+
												'</ul>';
								          	}else if(this.chailingbz == 0){
								          		kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" readonly="readonly" name="kaiyaodw" autocomplete="off">';
								          	}else if(this.chailingbz == 1){
								          		kelong +='<input value="'+this.kaiyaodw+'" class="wm-dosage dropdown-toggle cgmdc-input62" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" readonly="readonly" name="kaiyaodw" autocomplete="off" style="background-color:#fff;">'+
										          		'<ul class="dropdown-menu li-width f-input-li kaiyaodw"   style="display:none" role="menu">'+
														'<li>'+this.baozhuangdw+'</li>'+
														'<li>'+this.chailingdw+'</li>'+
														'</ul>';
								          	}
								          	kelong +='</td>'+
								        ' <td class="jine" >';
										if(this.zhensuoypid!=null) {
								        	kelong +='<input value="'+parseFloat(roundUtil(this.danjia, 8))+'" data-rule="金额:range[0~];length(~10)" type="text" data-target="#msg_holder"  name="jine" readOnly="true" class="input-jine cgmdc-input7 inp-select" autocomplete="off"> 元</td>';
								        }else{
								        	kelong +='<input value="'+parseFloat(roundUtil(this.danjia, 8))+'" data-rule="金额:range[0~];length(~10)" type="text" data-target="#msg_holder"  name="jine" class="input-jine cgmdc-input7 inp-select" autocomplete="off"> 元</td>';
								        }
										kelong +=
										'<input type="hidden" name="danjia" value="'+danjia+'">'+
										'<input type="hidden" name="chailingsl" value="'+this.chailingsl+'">'+
										'<input type="hidden" name="baozhuangdw" value="'+this.baozhuangdw+'">'+
										'<input type="hidden" name="shengchancj" value="'+this.shengchancj+'">'+
										'<input type="hidden" name="baozhuanggg" value="'+this.baozhuanggg+'">'+
										'<input type="hidden" name="gongyingshang" value="'+this.gongyingshang+'">'+
										'<input type="hidden" name="kucunsl" value="'+this.kucunsl+'">'+
										'<input type="hidden" name="jixing" value="'+this.jixing+'">'+
								        '<td> <img class="pointer2" src="'+path+'../image/shanc.png" alt=""></td>'+
								        '</tr>';
										
								}); 
								kelong +='<tr><td class="dropdown-search-li"><input type="text" class="wm-medicine-name cgmdc-input1 dropdown-toggle yaopinmc" autocomplete="off" data-rule="药品名称:length(1~100)" data-target="#msg_holder" name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,2)"><input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'"><div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
							    '<td class="dropdown-search-li"><input type="text" class="wm-group dropdown-toggle" cgmdc-input2 autocomplete="off" data-rule="组号:integer[+];range[~99]" data-target="#msg_holder"  name="zuhao"><ul class="dropdown-menu cgmz-jcts"style="width: 52px;" role="menu"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li><li>6</li><li>7</li><li>8</li><li>9</li></ul></td>'+
							    '<input type="hidden"  style="display:none;" name="zhensuoypid" >'+
							    '<input type="hidden"  style="display:none;" name="pingtaiypid" >'+
							    '<input type="hidden"  style="display:none;" name="ptuuid" >'+
							     '<td class="dropdown-search-li"><input type="text" class="input-sm  cgmdc-input3 dropdown-toggle yongfa" autocomplete="off" style="width:100%" id="chengy-yf'+(len+1)+'" name="yongfa" data-rule="成药用法:length(1~64)" data-target="#msg_holder"><ul class="dropdown-menu li-width f-input-li yongfaul"   style="display:none" role="menu"></ul></td>'+
							     '<td class="dropdown-search-li"><input class="wm-rate dropdown-toggle yongyypl cgmdc-input4" autocomplete="off" id="chengy-yongypl'+(len+1)+'" data-rule="用药频率:length(1~64)" data-target="#msg_holder" name="yongyaopl" onfocus="getZDYongyaoplBymc(this)" onkeyup="getZDYongyaoplBymc(this)"><ul class="dropdown-menu li-width f-input-li yongyyaoplul"  style="display:none" role="menu"></ul></td>'+
							     '<td class="wm-dosage-father dropdown-search-li">'+
							      	'<input type="text" class="wm-dosage cgmdc-input51" autocomplete="off" name="dancijl" data-rule="单次剂量:range[0~];length(~8)" data-target="#msg_holder"> ' + 
							      	'<input class="wm-dosage dropdown-toggle cgmdc-input52" autocomplete="off" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="dancijldw">'+
							      	'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
							      	'<li>片</li>'+
							 		'<li>粒</li>'+
							 		'<li>支</li>'+
							 		'<li>袋</li>'+
							 		'<li>丸</li>'+
							 		'<li>枚</li>'+
							 		'<li>瓶</li>'+
							 		'<li>滴</li>'+
							 		'<li>克</li>'+
						     		'<li>g</li>'+
							 		'<li>ml</li>'+
							 		'<li class="wushuju" style="padding-left:0;text-align:center;">适量</li>'+
									   '</ul>'+	
							     '</td>'+
							     '<td class="wm-dosage-father wm-dosage-father2 dropdown-search-li">'+
							      	'<input type="text" class="wm-number cgmdc-input61" autocomplete="off" name="kaiyaoliang" data-target="#msg_holder" onkeyup="jisuanypje(this)"> ' + 
							      	'<input class="wm-dosage dropdown-toggle cgmdc-input62" autocomplete="off" data-rule="剂量单位:length(1~10)" data-target="#msg_holder" name="kaiyaodw">'+
							      	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none" role="menu">'+
							      	'<li>盒</li>'+
							 		'<li>瓶</li>'+
							 		'<li>支</li>'+
							 		'<li>袋</li>'+
							 		'<li>丸</li>'+
							 		'<li>片</li>'+
							 		'<li>粒</li>'+
							 		'<li>板</li>'+
							 		'<li>克</li>'+
						     		'<li>g</li>'+
									   '</ul></td>'+
							    ' <td class="jine"><input  data-rule="金额:range[0~];length(~10)" autocomplete="off" data-target="#msg_holder" type="text" name="jine" class="input-jine cgmdc-input7 inp-select"> 元</td>'+
								'<input type="hidden" name="danjia" value="0">'+
								'<input type="hidden" name="chailingsl">'+
								'<input type="hidden" name="baozhuangdw">'+
								'<input type="hidden" name="shengchancj">'+
								'<input type="hidden" name="baozhuanggg" >'+
								'<input type="hidden" name="gongyingshang">'+
								'<input type="hidden" name="kucunsl">'+
								'<input type="hidden" name="jixing">'+
							    '<td> <div class="g-mz-delete pointer2" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'+path+'../image/shanc.png" alt=""></div></td>'+
							    '</tr>';
								kelong +='</tbody>'+
									     '</table>'+
										 '</div></div>';
								$(".western-medicine:last").after(kelong);//添加成药模板	
								$('[name="kaiyaoliang"]').trigger('keyup');	
			    			});
			    		}
			    		$(".chinese-medicine:not(:first)").remove();
			    		var exZsCaoyaocfs = data.exZsCaoyaocfs;
			    		if(exZsCaoyaocfs!="") {
			    			$(exZsCaoyaocfs).each(function(){
			    				var kelong ="";
			    				var zsCaoyaocf = this.zsCaoyaocf;
			    				var yaopins = this.exYaopins;
			    				var len=$(".chinese-medicine").length;
								 kelong='<div class="chinese-medicine g-m-chinese" id="chinese-medicine">'+
						          '<div class="chinese-head">'+zsCaoyaocf.mingcheng+'<span class="medicine-delete"> 删除处方</span></div>'+
						          '<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
						          '<input type="hidden" style="display:none;" name="mingcheng" value="'+zsCaoyaocf.mingcheng+'">'+
						          '<input type="hidden" class="chinese-paixu">'+
						          '<div class="medicine-herb">'+
					          		  '<input type="hidden" name="jixing" value="饮片">'+
						              '<div class="medicine-item">'+
							              	 	'<label class="l-ibt-label"><span class="glyph-star">*</span>剂数：</label>'+
							                  '<input id="tieshu" value="'+zsCaoyaocf.tieshu+'" type="text" class="m-inform" data-rule="剂数:required;range[1~];length(~2)" value="1" data-target="#msg_holder" name="tieshu" onkeyup="jiasuancaoyao(this)" autocomplete="off"> 剂/贴'+
							         '</div>' +
							          '<div class="medicine-item">'+
							              '<label ><span class="glyph-star">*</span>每日剂数：'+
							                  '<input value="'+zsCaoyaocf.meirijl+'" type="number" class="m-inform" data-rule="每日剂数:required;range[0~];length(~2)" data-target="#msg_holder"  name="meirijl" autocomplete="off"> 剂'+
							              '</label>'+
							         '</div>'+
							         '<div class="medicine-item dropdown-search-li">' +
							             '<label class="l-heart-rhythm">' +
							               '<span><span class="glyph-star">*</span>用药频率：</span>' +
							              '</label>'+
						                  '<input  value="'+zsCaoyaocf.yongyaopl+'" class="m-inform yongyypl dropdown-toggle" name="yongyaopl" data-rule="用药频率:required;length(1~64)" data-target="#msg_holder" onfocus="getZDYongyaoplBymc(this)"  onkeyup="getZDYongyaoplBymc(this)" autocomplete="off">' +
						                  '<ul class="dropdown-menu li-width f-input-li yongyyaoplul" id="yongfaul"  style="display:none; margin-bottom:0;" role="menu">'+
									  	 '</ul>'+
							        '</div>'      + 
						             '<div class="medicine-item mi-usage dropdown-search-li"> '+
						               '<span class="mitem-usage"><span class="glyph-star">*</span>用法：</span>' +
						                 '<input value="'+zsCaoyaocf.yongfa+'" class="m-inform dropdown-toggle yongfa" name="yongfa" data-rule="用法:required;length(1~64)"  data-target="#msg_holder" onfocus="getYongfazd(this)"  onkeyup="getYongfazd(this)" autocomplete="off"> ' +
						                 '<ul class="dropdown-menu li-width f-input-li yongfaul" id="yongfaul" style="display:none"  role="menu">' +
									  	 '</ul>'+
						            '</div>'+
						           '<div class="medicine-item medicine-item2x">' +
						               '<label for="input-else" class="l-ielse" style="margin-left: 2px;">服用要求：</label>' +
						                ' <input type="text" value="'+zsCaoyaocf.fuyongyq+'" class="m-inform" data-rule="用药频率:length(1~128)" data-target="#msg_holder" id="input-else" name="fuyongyq" autocomplete="off">' +
						           '</div>'+
						     '</div>' +
						     '<div style="margin:0 auto;">'+
						     ' <table class="table" id="caoyaoyp" style="table-layout:fixed;">'+
						        '<tbody>' ;
								var finali = yaopins.length;
								$(yaopins).each(function(i,m){
									/*if(this.chailingbz == 0){
										var danjia = parseFloat(chailingsl) * parseFloat(danjia);;
									}*/
									var danjia = this.danjia;
									if(danjia==null) {
										danjia = 0;
									}
									var shuliang = this.danjiliang;
									var jine = parseFloat(roundUtil(parseFloat(danjia), 8));
									jine = '￥'+jine;
									kelong +='<tr>'+
						        	'<td class="zymb-number">饮片'+(i+1)+'：</td>'+
						         	'<td class="zymb-td2 dropdown-search-li"><input type="text" value="'+this.yaopinmc+'" class="wm-medicine-name dropdown-toggle yaopinmc cgmdc-input1" data-rule="药品名称:length(1~100)" data-target="#msg_holder"  name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,1,event)" autocomplete="off">'+
						         	'<div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
						         	'<ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
						         	'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
						            '<td class="zymb-td3"><input value="'+this.danjiliang+'" type="text" placeholder="数量" class="wm-solo-dosage cgmdc-input2" name="danjiliang"  data-target="#msg_holder"  onkeyup="jisuanypje(this)" autocomplete="off">';
						            if(this.chailingbz == null){
						            	kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle" data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei" readonly="readonly" style="margin-left:5px;text-align: center;">'+
									            	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu">'+
													'<li>盒</li>'+
											   		'<li>瓶</li>'+
											   		'<li>支</li>'+
											   		'<li>袋</li>'+
											   		'<li>丸</li>'+
											   		'<li>片</li>'+
											   		'<li>粒</li>'+
											   		'<li>板</li>'+
											   		'<li>克</li>'+
											   		'<li>个</li>'+
											   		'</ul>';
						            }else if(this.chailingbz == 0){
											kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle " data-rule="单位:length(1~2)" autocomplete="off" data-target="#msg_holder" name="danwei" readonly="readonly" style="margin-left:5px;text-align: center;">';
						            }else  if(this.chailingbz == 1){
						            	kelong +='<input value="'+this.danwei+'" class="wm-dosage dropdown-toggle " data-rule="单位:length(1~2)" autocomplete="off" readonly="readonly" data-target="#msg_holder" name="danwei" style="margin-left:5px;text-align: center;background-color:#fff;">'+
												'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu">'+
												'<li>'+this.baozhuangdw+'</li><li>'+this.chailingdw+'</li></ul>';
						            }
						         	kelong +='</td>'+
						            '<td class="zymb-td4">'+
									    '<input class="dropdown-toggle" type="text" placeholder="备注" name="beizhu" value="'+this.beizhu+'">'+
										'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
											'<li>已取</li>'+
											'<li>口服</li>'+
											'<li>泡服</li>'+
											'<li>外用</li>'+
											'<li>先煎</li>'+
											'<li>后下</li>'+
											'<li>水煎</li>'+
											'<li>包煎</li>'+
											'<li>打碎</li>'+
											'<li>另包</li>'+
											'<li>吞服</li>'+
											'<li>另煎</li>'+
											'<li>烊化</li>'+
											'<li>冲服</li>'+
											'<li>内服</li>'+
											'<li>入丸</li>'+
										'</ul>'+
									'</td>'+
						            '<input type="hidden"  style="display:none;" name="zhensuoypid" value="'+this.zhensuoypid+'">'+
							        '<input type="hidden"  style="display:none;" name="pingtaiypid" value="'+this.pingtaiypid+'">'+
							        '<input type="hidden"  style="display:none;" name="ptuuid" value="'+this.ptuuid+'">'+
							        '<input type="hidden" name="kucunsl" value="'+this.kucunsl+'">'+
							        '<input type="hidden" name="chailingsl" value="'+this.chailingsl+'">'+
							        '<input type="hidden" name="baozhuangdw" value="'+this.baozhuangdw+'">'+
									'<input type="hidden" name="shengchancj" value="'+this.shengchancj+'">'+
									'<input type="hidden" name="baozhuanggg" value="'+this.baozhuanggg+'">'+
									'<input type="hidden" name="gongyingshang" value="'+this.gongyingshang+'">'+
							        ' <td class="jine" >';
									if(this.zhensuoypid!=null) {
							        	kelong +='<input data-toggle="popover" data-placement="bottom" data-content="" value="'+parseFloat(roundUtil(this.danjia, 8))+'" readOnly="true"  type="text" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" class="input-jine cgmdc-input3 inp-select" autocomplete="off"> 元</td>';
									}else{
							        	kelong +='<input data-toggle="popover" data-placement="bottom" data-content="" value="'+parseFloat(roundUtil(this.danjia, 8))+'"  type="text" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" class="input-jine cgmdc-input3 inp-select" autocomplete="off"> 元</td>';
							        }
									kelong +=
									'<input type="hidden" name="danjia" value="'+danjia+'">'+
						            '<td><img  class="pointer3" src="'+path+'../image/shanc.png" alt=""></td>'+
						            '</tr>';
								});  
								kelong += '<tr>'+
								'<td class="zymb-number">饮片'+(finali+1)+'：</td>'+
							 	'<td class="zymb-td2 dropdown-search-li"><input type="text" class="wm-medicine-name dropdown-toggle yaopinmc cgmdc-input1" style="text-align: left;" autocomplete="off" data-rule="药品名称:length(1~100)" data-target="#msg_holder"  name="yaopinmc" onblur="yaowuxk(this)" onkeyup="getYaopin(this,1)"><div class="g-wmfinp-warning"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><div class="g-wmfinp-danger"  data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div><ul class="dropdown-menu li-width f-input-li yaopinmcul"   style="display:none" role="menu"></ul></td>'+
							 	'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
							    '<td class="zymb-td3"><input type="text" placeholder="数量" class="wm-solo-dosage cgmdc-input2" autocomplete="off" name="danjiliang" data-target="#msg_holder"  onkeyup="jisuanypje(this)">'+
							    '<input class="wm-dosage dropdown-toggle" placeholder="单位" autocomplete="off" data-target="#msg_holder" name="danwei" style="margin-left:5px;text-align: center;">'+
						      	'<ul class="dropdown-menu li-width f-input-li kaiyaodw"  style="display:none;width:70px;left:77px;" role="menu">'+
							      	'<li>盒</li>'+
							   		'<li>瓶</li>'+
							   		'<li>支</li>'+
							   		'<li>袋</li>'+
							   		'<li>丸</li>'+
							   		'<li>片</li>'+
							   		'<li>粒</li>'+
							   		'<li>板</li>'+
							   		'<li>克</li>'+
							   		'<li>个</li>'+
							   		'</ul></td>'+
							    '<td class="zymb-td4">'+
								    '<input class="dropdown-toggle" type="text" placeholder="备注" name="beizhu">'+
									'<ul class="dropdown-menu li-width f-input-li dancijldw"   style="display:none" role="menu">'+
										'<li>已取</li>'+
										'<li>口服</li>'+
										'<li>泡服</li>'+
										'<li>外用</li>'+
										'<li>先煎</li>'+
										'<li>后下</li>'+
										'<li>水煎</li>'+
										'<li>包煎</li>'+
										'<li>打碎</li>'+
										'<li>另包</li>'+
										'<li>吞服</li>'+
										'<li>另煎</li>'+
										'<li>烊化</li>'+
										'<li>冲服</li>'+
										'<li>内服</li>'+
										'<li>入丸</li>'+
									'</ul>'+
								'</td>'+
							    '<input type="hidden"  style="display:none;" name="zhensuoypid" >'+
							    '<input type="hidden"  style="display:none;" name="pingtaiypid" >'+
							    '<input type="hidden"  style="display:none;" name="ptuuid" >'+
							    ' <td class="jine"><input  type="text" data-toggle="popover" data-placement="bottom" data-content="" data-rule="金额:range[0~];length(~10)" autocomplete="off" data-target="#msg_holder" name="jine" class="input-jine cgmdc-input3 inp-select"> 元</td>'+
								'<input type="hidden" name="danjia" value="0">'+
								'<input type="hidden" name="kucunsl">'+
								'<input type="hidden" name="chailingsl">'+
								'<input type="hidden" name="baozhuangdw">'+
								'<input type="hidden" name="shengchancj">'+
								'<input type="hidden" name="baozhuanggg">'+
								'<input type="hidden" name="gongyingshang">'+
							    '<td><div class="g-mz-delete pointer3" data-container="body" data-toggle="popover" data-placement="bottom"  data-content="清除本行"><img class="" src="'+path+'/image/shanc.png" alt=""></div></td>'+
							    '</tr>';  
								kelong +=
										  '</tbody>'+
									      '</table>' +
									      '</div>'+
											'<div class="clearfix" id="heji">'+
											'<span style="float:right;margin:0 30px 15px 0;">处方总金额：<span class="chufangzje">0.00元</span></span>'+
											'<span style="float:right;margin:0 30px 15px 0;">单剂总金额：<span class="danjizongje">0.00元</span></span>'+
											'<span style="float:right;margin:0 30px 15px 0;" >共计<span class="yaopingsl">0</span>味药</span>'+
											'</div>'+
											'</div>';
								
								$(".chinese-medicine:last").after(kelong);//添加成药模板
								$('[name="danjiliang"]').trigger('keyup');	
			    			});
			    		}
			    		/****        耗材部分       ****/
			    		var zsJiuzhenhcs = data.exZsJiuzhenhcs;
			    		if(zsJiuzhenhcs!="") {
			    			var haocaistr = '';
			    		
			    			$(zsJiuzhenhcs).each(function(){
			    				var danjia = this.danjia;
								if(danjia==null) {
									danjia = 0;
								}
			    				haocaistr+='<tr class="medicine-item-tr">'+
								'<td class="hzn-name-td2 dropdown-search-li">'+
								'<input type="text" value="'+this.mingcheng+'" class=" form-control dropdown-toggle hzn-name-input2 dropdowninput" id="haocaiName" data-rule="耗材名称:length(1~128)" autocomplete="off"  data-target="#msg_holder" name="mingcheng" onblur="jiancehc(this)">'+
								'<div class="g-wmfinp-warning" style="top:13px;right:17px;" data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
								'<ul class="dropdown-menu li-width f-input-li haocai"  style="top: 36px; width:159%; left:0; display: none;" role="menu">'+
						   		'</ul>'+
						   		'<input type="hidden" name="danjia" value="'+danjia+'">'+
									'<input type="hidden" value="'+this.paixu+'" class="wm-paixu" style="display:none;" name="paixu" >'+
									'<input type="hidden" name="pingtaihcid" value="'+this.pingtaihcid+'">'+
									'<input type="hidden" name="zhensuohcid" value="'+this.zhensuohcid+'">'+
									'<input type="hidden" name="shengchancj" value="'+this.shengchancj+'">'+
									'<input type="hidden" name="baozhuanggg" value="'+this.baozhuanggg+'">'+
									'<input type="hidden" name="gongyingshang" value="'+this.gongyingshang+'">'+
									'<input type="hidden" name="ptuuid" >'+
									'</td>'+
								'<td class="hzn-name hzn-name-td3 dropdown-search-li" style="padding-bottom:0;"><input value="'+this.shuliang+'" type="text" class=" form-control hzn-name-input3 dropdowninput shuliang" data-rule="数量:range[0~];length(~10)" data-target="#msg_holder" name="shuliang" onkeyup="jisuanhcje(this)" style="float:left;margin-right:10px;">';
								if(this.chailingbz == null){
									haocaistr+='<input type="text"  value="'+this.danwei+'" name="danwei" class="form-control hzn-name-input32 dropdown-toggle" id="cghc-fydw" style="width:70px;">'+
									'<ul class="dropdown-menu li-width hcdanwei" id="cghc-fydw-ul" role="menu" style="top:35px;">'+
									'<li>盒</li>'+
									'<li>瓶</li>'+
									'<li>支</li>'+
									'<li>袋</li>'+
									'<li>丸</li>'+
									'<li>片</li>'+
									'</ul>'+
									'</td>';
								}else if(this.chailingbz == 0){
									haocaistr+='<input type="text"  value="'+this.danwei+'" name="danwei" class="form-control hzn-name-input32 dropdown-toggle" id="cghc-fydw" readonly="readonly" style="width:70px;">';
								}else if(this.chailingbz == 1){
									haocaistr+='<input type="text"  value="'+this.danwei+'" name="danwei" class="form-control hzn-name-input32 dropdown-toggle" id="cghc-fydw" readonly="readonly" style="width:70px;background-color:#fff;">'+
									'<ul class="dropdown-menu li-width hcdanwei" id="cghc-fydw-ul" role="menu" style="top:35px;">'+
									'<li>'+this.baozhuangdw+'</li>'+
									'<li>'+this.chailingdw+'</li>'+
									'</ul>';
								}
								var haocaije=parseFloat(roundUtil(parseFloat(this.danjia), 8));
			    				haocaistr+='<td class="hzn-name-td4">'+
									'<span class="cgl3-td-number">金额</span>';
			    				if(this.zhensuohcid!=null) {
			    					haocaistr +='<input type="text" readOnly="true" value="'+haocaije+'" class=" form-control hzn-name-input4 jine inp-select" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" >  元';
			    				}else{
			    					haocaistr +='<input type="text" value="'+haocaije+'" class=" form-control hzn-name-input4 jine inp-select" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" >  元';
			    				}
			    				
			    				haocaistr +='<input type="hidden" name="chailingsl" value="'+this.chailingsl+'">'+
									'<input type="hidden" name="baozhuangdw" value="'+this.baozhuangdw+'">'+
									'<input type="hidden" name="kucunsl" value="'+this.kucunsl+'">'+
									'</td>'+
								'<td style="text-align: left;"><img class="pointer31" src="'+path+'/image/shanc.png" alt=""></td>'+
								'</tr>';
			    				
			    			});
			    			$('#haocai').html("");
				    		$('#haocai').append(haocaistr);
				    		$('[name="shuliang"]').trigger('keyup');
			    		}else{
			    			var len=$('#haocai').length;
			    			haocaistr +='<tr class="medicine-item-tr">'+
							'<td class="hzn-name-td2 dropdown-search-li">'+
							'<input type="text" class=" form-control dropdown-toggle hzn-name-input2 dropdowninput" id="haocaiName" data-rule="耗材名称:length(1~128)"  data-target="#msg_holder" name="mingcheng" onblur="jiancehc(this)" autocomplete="off">'+
							'<div class="g-wmfinp-warning" style="top:13px;right:17px;" data-container="body" data-toggle="popover" data-placement="bottom"  data-content=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></div>'+
							'<ul class="dropdown-menu li-width f-input-li haocai"  style="top: 36px; width: 159%; left:0; display: none;" role="menu">'+
					   		'</ul>'+
					   		'<input type="hidden" name="danjia" >'+
							'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="1">'+
							'<input type="hidden" name="pingtaihcid" >'+
							'<input type="hidden" name="zhensuohcid" >'+
							'<input type="hidden" name="shengchancj" >'+
							'<input type="hidden" name="baozhuanggg" >'+
							'<input type="hidden" name="gongyingshang">'+
							'<input type="hidden" name="ptuuid" >'+
							'</td>'+
							'<td class="hzn-name hzn-name-td3 dropdown-search-li" style="padding-bottom:0;"><input type="text" class=" form-control hzn-name-input3 dropdowninput shuliang" placeholder="数量"  data-target="#msg_holder" name="shuliang" onkeyup="jisuanhcje(this)" autocomplete="off" style="float:left;margin-right:10px;">'+
							'<input type="text" name="danwei" class="form-control hzn-name-input32 dropdown-toggle" id="cghc-fydw" placeholder="单位" style="width:70px;" autocomplete="off">'+
								'<ul class="dropdown-menu li-width hcdanwei" id="cghc-fydw-ul" role="menu" style="top:35px;">'+
						      '<li>盒</li>'+
							  '<li>瓶</li>'+
							  '<li>支</li>'+
							  '<li>袋</li>'+
							  '<li>丸</li>'+
							  '<li>片</li>'+
							  '</ul>'+
							'</td>'+
							'<td class="hzn-name-td4">'+
								'<span class="cgl3-td-number">金额</span><input type="text" class=" form-control hzn-name-input4 jine inp-select" data-rule="金额:range[0~];length(~10)" data-target="#msg_holder" name="jine" value="0.00" autocomplete="off">  元'+
								'<input type="hidden" name="chailingsl">'+
								'<input type="hidden" name="baozhuangdw">'+
								'<input type="hidden" name="kucunsl" >'+
								'</td>'+
							'<td style="text-align: left;"><img class="pointer31" src="'+path+'/image/shanc.png" alt=""></td>'+
							'</tr>';
		    				$('#haocai').html("");
				    		$('#haocai').append(haocaistr);
			    		}
			    		/****        附加费、检查项部分       ****/
			    		var zsJiuzhenjcxs = data.zsJiuzhenjcxs;
			    		jianchaxStr = '';
			    		if(zsJiuzhenjcxs!="") {
			    			$(zsJiuzhenjcxs).each(function(){
			    				jianchaxStr += '<tr class="medicine-item-tr">'+
				    			'<td class="hzn-name-td2 dropdown-search-li">'+
				    			'<input type="text" class=" form-control hzn-name-input2 dropdowninput dropdown-toggle" id="jianchaName" data-rule="诊疗名称:length(1~128)" data-target="#msg_holder"  name="mingcheng" value="'+this.mingcheng+'" autocomplete="off"><ul class="dropdown-menu li-width f-input-li fujiaf"   style="display:none;top: 36px;left:0; width: 90%;" role="menu"></ul>'+
				    			'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+this.paixu+'">'+
				    			'<input type="hidden" name="pingtaijcxid" id="hipingtaijcxid" value="'+this.pingtaijcxid+'"><input type="hidden" name="zhensuojcxid" id="hizhensuojcxid" value="'+this.zhensuojcxid+'">'+
				    			'</td>';
			    				
				    			if(this.jine!=null&&this.jine!=''||this.jine=="0"){
									var jianchaxje=parseFloat(roundUtil(parseFloat(this.jine), 8));
								}
				    			jianchaxStr +='<td class="hzn-name-td4">'+
				    			'<span class="cgl3-td-number">金额</span>';
			    				if(this.zhensuojcxid!=null) {
			    					jianchaxStr +='<input type="text" readOnly="true" class=" form-control hzn-name-input4 jine inp-select" value="'+jianchaxje+'"  name="jine" autocomplete="off"> 元</td>';
			    				}else{
			    					jianchaxStr +='<input type="text" class=" form-control hzn-name-input4 jine inp-select" value="'+jianchaxje+'"  name="jine" autocomplete="off"> 元</td>';
			    				}
				    			
			    				jianchaxStr +='<td style="text-align: left;"><img class="pointer33" src="'+path+'/image/shanc.png" alt=""></td>'+
				    			'</tr>';
				    		
				    		});
				    		$('#jiancx').html("");
				    		$('#jiancx').append(jianchaxStr);
			    		}else{
			    			var len=$('#jiancx').length;
			    			jianchaxStr += '<tr class="medicine-item-tr">'+
			    			'<td class="hzn-name-td2 dropdown-search-li">'+
			    			'<input type="text" class=" form-control hzn-name-input2 dropdowninput dropdown-toggle" id="jianchaName" data-rule="诊疗名称:length(1~128)" data-target="#msg_holder"  name="mingcheng" autocomplete="off"><ul class="dropdown-menu li-width f-input-li jianchax"   style="top: 36px; width: 90%;left:0; display: none;" role="menu"></ul>'+
			    			'<input type="hidden" class="wm-paixu" style="display:none;" name="paixu" value="'+(len+1)+'">'+
			    			'<input type="hidden" name="pingtaijcxid" id="hipingtaijcxid"><input type="hidden" name="zhensuojcxid" id="hizhensuojcxid">'+
			    			'</td>'+
			    			'<td class="hzn-name-td4">'+
			    			'<span class="cgl3-td-number">金额</span><input type="text" class=" form-control hzn-name-input4 jine inp-select"  name="jine" value="0.00" autocomplete="off"> 元</td>'+
			    			'<td style="text-align: left;"><img class="pointer33" src="'+path+'/image/shanc.png" alt=""></td>'+
			    			'</tr>';
			    			$('#jiancx').html("");
			    			$('#jiancx').append(jianchaxStr);
			    		}
			    		
			    		 zhuangtai = data.zsJiuzhenjl.zhuangtai;
			    		if(isYinyong==0) {
			    			$('.cgmz-l-ignore').remove();
			    			$(".btn-lbc").css("display","inline-block");
			    			$(".btn-lbc2").css("display","inline-block");
			    			if (isYiBao && isKeHud) {
				    			$("#yibao-yujies").css("display","inline-block");
			    			} else {
			    				$("#yibao-yujies").css("display","none");
			    			}
			    		}else{
			    			saveOrUpdate = 1;//修改标志设为修改
			    			jiuzhenjlid = jiuzhenid;
			    			if(zhuangtai==3||zhuangtai==2) {
				    			var ignoreDiv = '<div class="cgmz-l-ignore"><div>';
				    			var iheight =$('.l-side').height();
				    			$('.l-side').append(ignoreDiv);
				    			$(".btn-lbc").css("display","none");
				    			$(".btn-lbc2").css("display","none");
				    			$('.cgmz-l-ignore').css('height',iheight+"px");
				    			if(exZsChengyaocfs.length !=0 || exZsCaoyaocfs.length !=0){
				    				$('#btnDayincf').css('display','inline-block');
				    			}
				    		}else if(zhuangtai==1){//今日门诊保存状态
				    			$('.cgmz-l-ignore').remove();
				    			$("#btnBcAndSf").css("display","inline-block");
				    			if (isYiBao && isKeHud) {
					    			$("#yibao-yujies").css("display","inline-block");
				    			} else {
				    				$("#yibao-yujies").css("display","none");
				    			}
				    			$(".btn-lbc2").css("display","inline-block");
				    			$("#inputname").attr("readonly","readonly");
								$("#deleteHuanzhe").css("display","block");
				    			if(exZsChengyaocfs.length !=0 || exZsCaoyaocfs.length !=0){
				    				$('#btnDayincf').css('display','inline-block');
				    			}

				    		}
			    		}
			    		/*金额部分======================================*/
			    		//合计金额
			    		//$('#sphejije').text(getFloatStr(data.zsJiuzhenjl.hejije)+'元');
			    		var jine = 0.00;
			    		$('#formSave').find('[name="jine"]').each(function (){
			    			var ifFather = $(this).parent().parent().parent().parent().parent().parent().hasClass('chinese-medicine');
			    			var tieshushuliang = $(this).parents('#chinese-medicine').find('#tieshu').val();
			    			var Thisval = $(this).val();
			    			if(ifFather){
			    				jine = parseFloat(jine) + parseFloat(multiply(Thisval, tieshushuliang));
			    			}else{
			    				if($(this).val()!="") {
			    					jine = parseFloat(jine) + parseFloat(Thisval);
			    				}
			    			}
			    		});
			    		jine=roundUtil(jine, 2);
			    		if($('#sphejije').text()!= jine+'元'){
			    			if(jine){
			    				$('#sphejije').text(jine+'元');
			    			}else{
			    				$('#sphejije').text('0.00元');
			    			}
			    		}
			    		
			    		// 校验所有项目是否对照
			    		$.ajax({
			    	        type:"POST",
			    	        url:path+"/yibao/validateYbxmbm",
			    	        data:{jiuzhenjlid:jiuzhenjlid},
			    	        async:false,
			    	        success: function(data){
			    	        	if(data == "fail") {
			    	        		notifyWarning("系统开小差啦~");
			    	        	}else if(data != "") {
			    	        		allowYbYujs = data;
			    	        		// 医保目录还未对照
			    	        		$('#jz-yibaojs-content').val("fail");
			    	        	}else{
			    	        		allowYbYujs = "";
			    	        		// 加载部分预结算信息
			    	        		var zhenduanStr = "";
			    	        		$(zsJiuzhenzds).each(function(){
			    	        			zhenduanStr += this.jibingmc + ",";
			    	        		});
			    	        		$("#ybYujies_zhenduan").text(zhenduanStr);
			    	        		$("#ybYujies_xingming").text(huanzhexx.xingming);			    	        		
			    	        		if(huanzhexx.xingbie==1) {
			    	        			$("#ybYujies_xingbie").text("男");
						    		}else if(huanzhexx.xingbie==2){
						    			$("#ybYujies_xingbie").text("女");
						    		}			    	        		
			    	        		$("#ybYujies_nianling").text(huanzhexx.nianling + huanzhexx.nianlingdw);
			    	        		$("#ybYujies_shoujih").text(huanzhexx.shoujihm);
			    	        		
						    		//将医保费用结算数据放置在页面上
						    		$.ajax({
						    		    type:"get",
						    		    url:path+"/yibao/packageYbfyjscs",
						    		    data:{jiuzhenjlid:jiuzhenid},
						    		    dataType:"json",
						    		    async:false,
						    		    success: function(data){
						    		    	$('#jz-yibaojs-content').val(data);
						    		    }
						    		});
			    	        	}
			    	        }
			    	    });
						jisuanYmje();
					}
			    }
			});
			$('.r-side').css('display','none');
			$('.huanz-message-down').hide();
			$("input:text").attr("autocomplete","off");
		}
		
	}
	// 打印处方
	$('#btnDayincf').click(function(){
		$.post(path+"/dayinsz/getDayinszYsByLx",{leixing: 1},function(result){
			if(result.succsess) {
				if(result.data == 3) {// 有主诉
					printChufangYouZhuSu(jiuzhenjlid,$('#inputname'));
				}else if(result.data == 4) {// 无主诉
					printChufang(jiuzhenjlid,$('#inputname'));
				}
			}
		})
	})
	
	var saveOrUpdate = 0;//用来标示新增还是修改，默认0新增
	//点击保存时
	function huoQuGuangBiao(yuanshu,msg,loading){
		notifyWarning(msg);
		yuanshu.focus();
		loading.css({"display":"none","z-index":"5"});
	};
    $('#formSave').validator({
        ignore: ':hidden',
        fields: {
    		'xingming':'姓名:length(1~64)',
    		'leixing':'checked',
    		'kaiyaoliang':'开药量:range(0~);length(~8)',
    		'danjiliang':'单剂量:range(0~);length(~8)',
    		'shuliang':'单剂量:range(0~);length(~10)'
    	},
    });
    // pointer2/3点击时添加（解决光标定在药品时点击删除保存不了的问题）
    var xuanzeypFlagbf = true;
    var yaowuxktxbz = false;
	$("#ywxk-save").click(function(){
		$("#yaowuxktsxx").modal("hide");
		yaowuxktxbz = true;
		if($('#hizhuangtai').val() == 1 && $('#hiisBaocun').val() == 1) {
			$("#btnBaocun").trigger("click");
		}
		if($('#hizhuangtai').val() == 2 && $('#hiisBaocun').val() == 0) {
			$('#formSave').trigger("validate");
		}
	});
	$("#ywxk-cancel").click(function(){
		$("#yaowuxktsxx").modal("hide");
	})
	vilidateform();
    function vilidateform() {
	   	  $('.l-form').on('valid.form', function(e){
 			$("#msg_holder").html(""); 
 			$('#hicaoyaocf').val(divDataToJson('chinese-medicine'));
 			$('#hichengyaocf').val(divDataToJson('western-medicine'));
 			//$('#hifujiaf').val(tableDataToJson('fujiaf'));
 			$('#hihaocai').val(tableDataToJson('haocai'));
 			$('#hijianchax').val(tableDataToJson('jiancx'));
 			$('#hizsJiuzhenzd').val(getZhenduanstr());
 			$('#hinianlingdw').val($('#f-le-nianlingdw').text());
 			$('#hituxiangzl').val(JSON.stringify(imgInfo));
 			$('#hikeys').val(JSON.stringify(keyArry));
 			
 			var caoyaoObj = JSON.parse($('#hicaoyaocf').val());
 			var yaowuxkxx = "";
 			for(var i = 0; i < caoyaoObj.length; i++) {
 				var yaopins = caoyaoObj[i].yaopins;
 				var arr = new Array();
 				for(var j = 0; j < yaopins.length; j++) {
 					arr.push(yaopins[j].yaopinmc);
 				}
 				var msg = getCaoyaoywxk(arr.join(","));
 				if(msg != "") {
 					yaowuxkxx += msg;
 				}
 			}
 			if(!yaowuxktxbz &&!!yaowuxkxx) {
 				$("#xiangxixx").text(yaowuxkxx);
 				$("#yaowuxktsxx").modal("show");
 				return false;
 			}
 			
 			// 保存在平台选择药品数据按药品分成数组
 		    var pingtaiypzyJiHe = [];
 			var pingtaiypxyJiHe = [];
 			if($('#f-le-fenlei2').text()=="心律正常") {
 				$('#hixinlvzb').val(1);
 			}else{
 				$('#hixinlvzb').val(0);
 			};
 			var oYanZheng = $('.cgmz-l2zd-dropdown').find('.cgmz-l2zd-dropmain').html();
 			var guangBiao = true;
 			var shoujihm = $('#inputphone').val();
 			if(shoujihm!=''&&huanzheid==null) {
 				$.ajax({
 		    		url:'./huanzhe/getHuanzheByxmAndsj',
 		    		type:'post',
 		    		data:{shoujihm:shoujihm},
 		    		async:false,
 		    		success:function(data) {
 		    			if(data.length>0) {
 		    				huoQuGuangBiao($('#inputphone'),'该手机号码已存在',$("#loading"));
 		    				guangBiao = false;
 		    				return false;
 		    			}
 		    		}
 		    	});
 			}
 			if(oYanZheng==undefined&&guangBiao){
 				huoQuGuangBiao($('#input-diagnosis'),'您还没填诊断',$("#loading"));
				guangBiao = false;
  			  return false;
  		   }
 			
 		    $('.img-item-time').each(function(){
 		    	var isDataOkTime =$(this).text();
 		    	console.log(isDataOkTime+"isDataOkTime")
 	 			if(!isDataOkTime){
 	 				notifyWarning("请填写完图片资料日期！");
 	 				guangBiao = false;
 	 				return false;
 	 			}
 		    });
 		    $('.img-item-name').each(function(){
 		    	var isDataOkType =$(this).find('span').text();
 		    	console.log(isDataOkType+"isDataOkType")
 		    	if(isDataOkType=="请在详情中确认类型"){
 	 				notifyWarning("请填写完图片资料类型！");
 	 				guangBiao = false;
 	 				return false;
 	 			}
 		    }); 
 		 //成药处方
		$('.western-medicine').each(function(){
			$(this).find("tbody tr").each(function(){
  				var yz1=$(this).find('.cgmdc-input1').val();
  				var yz2=$(this).find('.cgmdc-input2').val();
  				var yz3=$(this).find('.cgmdc-input3').val();
  				var yz4=$(this).find('.cgmdc-input4').val();
 	  			var yz51=$(this).find('.cgmdc-input51').val();
  				var yz52=$(this).find('.cgmdc-input52').val();
  				var yz61=$(this).find('.cgmdc-input61').val();
  				var yz62=$(this).find('.cgmdc-input62').val();
  				var yz7=$(this).find('.cgmdc-input7').val();
  				if(yz1!=""||yz3!=""||yz4!=""||yz51!=""||yz52!=""||yz61!=""||yz62!=""||yz7!=""){
  					if(yz1==""){
  						$(this).find('.cgmdc-input1').addClass('n-invalid');
 	  					if(guangBiao)
 	  					huoQuGuangBiao($(this).find('.cgmdc-input1'),'请完成成药名称',$("#loading"));
 	  					guangBiao = false;
  					}
  					if(yz3==""){
  					$(this).find('.cgmdc-input3').addClass('n-invalid');
 	  				if(guangBiao)
 	  				huoQuGuangBiao($(this).find('.cgmdc-input3'),'请完成成药用法',$("#loading"));
 	  				guangBiao = false;
  					}
  					if(yz4==""){
  					$(this).find('.cgmdc-input4').addClass('n-invalid');
 	  				if(guangBiao)
 	  				huoQuGuangBiao($(this).find('.cgmdc-input4'),'请完成成药用药频率',$("#loading"));
 	  				guangBiao = false;
  					}
 	  				if(yz51==""){
	 	 	  			if(guangBiao){
	 	 	  				if($(this).find('.cgmdc-input52').val()=="适量"){	
	 	 	  				}else{
	 	 	  				$(this).find('.cgmdc-input51').addClass('n-invalid');
	 	 	  					huoQuGuangBiao($(this).find('.cgmdc-input51'),'请完成成药每次剂量数',$("#loading"));
	 	 	  					guangBiao = false;
	 	 	  				}
	 	 	  			}
  					}
  					if(yz52==""){
  					$(this).find('.cgmdc-input52').addClass('n-invalid');
 	  				if(guangBiao)
 	  				huoQuGuangBiao($(this).find('.cgmdc-input52'),'请完成成药每次剂量单位',$("#loading"));
 	  				guangBiao = false;
  					}
  					if(yz61==""){
  					$(this).find('.cgmdc-input61').addClass('n-invalid');
 	  				if(guangBiao)
 	  				huoQuGuangBiao($(this).find('.cgmdc-input61'),'请完成成药开药数量',$("#loading"));
 	  				guangBiao = false;
  					}
 	  				if(yz62==""){
 	  				$(this).find('.cgmdc-input62').addClass('n-invalid');
 	 	  			if(guangBiao)
 	 	  			huoQuGuangBiao($(this).find('.cgmdc-input62'),'请完成成药开药单位',$("#loading"));
 	 	  			guangBiao = false;
  					}
  					if(yz7==""){
  					$(this).find('.cgmdc-input7').addClass('n-invalid');
  					if(guangBiao)
  					huoQuGuangBiao($(this).find('.cgmdc-input7'),'请完成成药金额',$("#loading"));
  					guangBiao = false;
  					}
  					
  				}

			});
		});
 	 		//草药处方
 	 			$('.chinese-medicine').each(function(){
 	 				$(this).find("tbody tr").each(function(){
 	 	  				var yz1=$(this).find('.cgmdc-input1').val();
 	 	  				var yz2=$(this).find('.cgmdc-input2').val();
 	 	  				var yz22=$(this).find('[name="danwei"]').val();
 	 	  				var yz3=$(this).find('.cgmdc-input3').val();
 	 	  				if(yz1!=""||yz2!=""||yz3!=""||yz22!=""){
 	 	  					if(yz1==""){
 	 	  						$(this).find('.cgmdc-input1').addClass('n-invalid');
	 	 	  					if(guangBiao)
	 	 	  					huoQuGuangBiao($(this).find('.cgmdc-input1'),'请完成饮片名称',$("#loading"));
	 	 	  						guangBiao = false;
 	 	  					}
 	 	  					if(yz2==""){
 	 	  					$(this).find('.cgmdc-input2').addClass('n-invalid');
	 	 	  				if(guangBiao)
	 	 	  				huoQuGuangBiao($(this).find('.cgmdc-input2'),'请完成饮片数量',$("#loading"));
	 	 	  				guangBiao = false;
 	 	  					}
	 	 	  				if(yz22 == ""){
		 	  					$(this).find('[name="danwei"]').addClass('n-invalid');
	 	 	  				if(guangBiao)
	 	 	  				huoQuGuangBiao($(this).find('[name="danwei"]'),'请完成饮片单位');
	 	 	  				guangBiao = false;
	 	  					}
 	 	  					if(yz3==""){
 	 	  					$(this).find('.cgmdc-input3').addClass('n-invalid');
	 	 	  				if(guangBiao)
	 	 	  				huoQuGuangBiao($(this).find('.cgmdc-input3'),'请完成饮片金额',$("#loading"));
	 	 	  				guangBiao = false;
 	 	  					}
 	 	  					if(yz1==""||yz2==""||yz3==""){
 	 	  	  	  			  return false;
 	 	  					}
 	 	  				}
 	 					
 	 				})
 	 			});
 	 			//草药处方
	 			$('.chinese-medicine').each(function(){
	 				$(this).find("tbody tr").each(function(){
	 	  				var yz1=$(this).find('.cgmdc-input1').val();
	 	  				var yz2=$(this).find('.cgmdc-input2').val();
	 	  				var yz3=$(this).find('.cgmdc-input3').val();
	 	  				if(yz1!=""||yz2!=""||yz3!=""){
	 	  					if(yz1==""){
	 	  						$(this).find('.cgmdc-input1').addClass('n-invalid');
 	 	  					if(guangBiao)
 	 	  					huoQuGuangBiao($(this).find('.cgmdc-input1'),'请完成饮片名称',$("#loading"));
 	 	  						guangBiao = false;
	 	  					}
	 	  					if(yz2==""){
	 	  					$(this).find('.cgmdc-input2').addClass('n-invalid');
 	 	  				if(guangBiao)
 	 	  				huoQuGuangBiao($(this).find('.cgmdc-input2'),'请完成饮片数量',$("#loading"));
 	 	  				guangBiao = false;
	 	  					}
	 	  					if(yz3==""){
	 	  					$(this).find('.cgmdc-input3').addClass('n-invalid');
 	 	  				if(guangBiao)
 	 	  				huoQuGuangBiao($(this).find('.cgmdc-input3'),'请完成饮片金额',$("#loading"));
 	 	  				guangBiao = false;
	 	  					}
	 	  					if(yz1==""||yz2==""||yz3==""){
	 	  	  	  			  return false;
	 	  					}
	 	  				}
	 					
	 				})
	 			});
	 	 		//耗材费用验证
	 	 			$('#haocai').find("tr").each(function(i,domDiv){
	 	  				var yz1=$(this).find('.hzn-name-input2').val();
	 	  				var yz2=$(this).find('.hzn-name-input3').val();
	 	  				var yz3=$(this).find('.hzn-name-input4').val();
	 	  				var yz4=$(this).find('.hzn-name-input32').val();
	 	  				if(yz1!=""||yz2!=""||yz4!=""||yz3>0){
	 	  					if(yz1==""){
	 	  						$(this).find('.hzn-name-input2').addClass('n-invalid');
	 	  						if(guangBiao)
	 	  							huoQuGuangBiao($(this).find('.hzn-name-input2'),'请完成耗材名称',$("#loading"));
	 	  						guangBiao = false;
	 	  					}
	 	  					if(yz2==""){
	 	  						$(this).find('.hzn-name-input3').addClass('n-invalid');
	 	  						if(guangBiao)
	 	  							huoQuGuangBiao($(this).find('.hzn-name-input3'),'请完成耗材数量',$("#loading"));
	 	  						guangBiao = false;
	 	  					}
	 	  					if(yz4==""){
	 	  						$(this).find('.hzn-name-input32').addClass('n-invalid');
	 	  						if(guangBiao)
	 	  							huoQuGuangBiao($(this).find('.hzn-name-input32'),'请完成耗材单位',$("#loading"));
	 	  						guangBiao = false;
	 	  					}
	 	  				}
	 	  			   });
	 	 			//检查治疗项
	 		 	 			$('#jiancx').find("tr").each(function(i,domDiv){
	 		 	 				var yz1=$(this).find('.hzn-name-input2').val();
	 		 	  				var yz3=$(this).find('.hzn-name-input4').val();
	 		 	  				if(yz3>0){
	 		 	  					if(yz1==""){
	 		 	  						$(this).find('.hzn-name-input2').addClass('n-invalid');
	 		 	  						huoQuGuangBiao($(this).find('.hzn-name-input2'),'请完成诊疗项名称',$("#loading"));
	 		 	  						guangBiao = false;
	 		 	  	  	  			  return false;
	 		 	  					}
	 		 	  				}
	 		 	  			   });
 			if($("#sphejije").text()=="0.00元"&&guangBiao&&$('#hizhuangtai').val()!=1){
 				notifyWarning("合计金额为0.00元，请检查药单是否正确");
 				$("#loading").css({"display":"none","z-index":"5"});
 				guangBiao = false;
 			}	
 			//判断是否点击了删除按钮
 			if(!xuanzeypFlagbf){
				xuanzeypFlag = true;
			}
 			if(saveOrUpdate==0&&guangBiao&&xuanzeypFlag) {
 				//按钮不可重复点击
 				if($('#hizhuangtai').val()==2) {
 					//设置收费按钮不可点击
 				$('#btnBaocun').attr('disabled',true);
 				}else{
 					//设置保存按钮不可点击
					$('#btnBaocun').attr('disabled',true);
 				}
 				$.ajax({
 				  url:'./changguimz/xinjiancgmz',
 				  type:'post',
 				  async:false,
 				  beforeSend: function () {
 					$("#loading").css({"display":"block","z-index":"5"});
				  },
				  complete: function () {
					$("#loading").css({"display":"none","z-index":"5"})
				  },
 				  data:$('#formSave').serializeArray(),
 				  success:function(data) {
 					 if(data.jinebyz) {
 						 $('#btnBaocun').removeAttr('disabled');
 						 $('#btnShoufei').removeAttr('disabled');
 						 notifyWarning('处方中存在名称相同的药品，但金额不同，请修改');
 					  }else{
 						 var sjc=new Date().getTime(); 
 	 					if(qx_shoukuan&&$('#hizhuangtai').val()==2) {//有收费的权限并且是收费,跳转到收费页面
 	 						window.location.href= path+'/jump/toShoufeixq?type=changguimz&ID='+data.shoufeijlid;
 	 					}else if(!qx_shoukuan&&$('#hizhuangtai').val()==2){//没有有收费的权限并且是收费,
 	  						//收费成功提示
 	  						var presuccmsg=encodeURI(encodeURI('已提交给收费人员'));
 	  						window.location.href=  path+'/jump/toChangguimz?msg='+presuccmsg+'&sjc='+sjc;
 	  	 				  	return false;
 	  					}else if($('#hizhuangtai').val()==1){
 	  						//保存成功提示
 	  						var presuccmsg=encodeURI(encodeURI('保存成功'));
 	  						window.location.href=  path+'/jump/toChangguimz?msg='+presuccmsg+'&sjc='+sjc;
 	  	 				  	return false;
 	  					}
 					  }
 				  }
 				});
 			}else if(guangBiao&&xuanzeypFlag){
 				//按钮不可重复点击
 				if($('#hizhuangtai').val()==2) {
 					//设置收费按钮不可点击
 				$('#btnBaocun').attr('disabled',true);
 				}else{
 					//设置保存按钮不可点击
					$('#btnBaocun').attr('disabled',true);
 				}
 				$('#hijiuzhenjlid').val(jiuzhenjlid);
 				$.ajax({
 				  url:'./changguimz/xiugaicgmz',
 				 beforeSend: function () {
 	 					$("#loading").css({"display":"block","z-index":"5"})
 	 					 },
 	 					 complete: function () {
 	 					$("#loading").css({"display":"none","z-index":"5"})
 	 					 },
 				  type:'post',
 				  data:$('#formSave').serializeArray(),
 				  success:function(data) {
 					 if(data.jinebyz) {
 						 $('#btnBaocun').removeAttr('disabled');
 						 $('#btnShoufei').removeAttr('disabled');
 						 notifyWarning('处方中存在名称相同的药品，但金额不同，请修改');
 					  }else{
 						 var sjc=new Date().getTime(); 
 	 					 if(qx_shoukuan&&$('#hizhuangtai').val()==2) {//有收费的权限并且是收费,跳转到收费页面
 	  						window.location.href= path+'/jump/toShoufeixq?type=changguimz&ID='+data.shoufeijlid;
 	  					}else if(!qx_shoukuan&&$('#hizhuangtai').val()==2){//没有有收费的权限并且是收费,
 	  						//收费成功提示
 	  						var presuccmsg=encodeURI(encodeURI('已提交给收费人员'));
 	  						window.location.href=  path+'/jump/toChangguimz?msg='+presuccmsg+'&sjc='+sjc;
 	  	 				  	return false;
 	  					}else if($('#hizhuangtai').val()==1){
 	  						//保存成功提示
 	  						var presuccmsg=encodeURI(encodeURI('保存成功'));
 	  						window.location.href=  path+'/jump/toChangguimz?msg='+presuccmsg+'&sjc='+sjc;
 	  	 				  	return false;
 	  					}
 					  }
 				  }
 				});
 			}
	  	
	});
	
  }
	//点击保存并收费时
	$('#btnBcAndSf').click(function(){
		A=0;
		$('#hizhuangtai').val(2);
		$('#hiisBaocun').val(0);
		//新加提示圈圈
		
	});
	$('#btnBaocun').click(function(){
		A=0;
		$('#hizhuangtai').val(1);
		$('#hiisBaocun').val(1);
		//新加提示圈圈.
	});
	//取消时
	var A = 0;
	$("form").keyup(function(){
		A++;
	});	
	window.onbeforeunload = function(){
			 if(A>0){
				 return false;
			 }
	};
	$('#btnQuxiao').click(function(){
		if(zhuangtai==3||zhuangtai==2){
			A=0;
		};
		if(A>0){
				$("#cgmz-form-info").modal();
		}else{
				window.location.href=  path+'/jump/toChangguimz';
			}
		});
	
	$("#cgmz-form-queding").click(function(){
		//A=0;
		$("#cgmz-form-info").modal('hide');
		window.location.href=  path+'/jump/toChangguimz';
	});
	
	
	//心率与心率指标联动
	function zhibld(obj) {
		var val = $(obj).val();
		if(val>=60&&val<=100) {
			$('#f-le-fenlei2').text("心率正常");
		}else{
			$('#f-le-fenlei2').text("心率不齐");
		}
	}
	
	
	//加载今日门诊-分页
	changguimz_exeShowPage();
	function changguimz_exeShowPage(){
	var totalNumber = 0;
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url:path+"/changguimz/getCount",
	    //传送数据
	    data:{zhuangtai:0,yewurk:1},
	    async:false,
	    //请求成功完成后要执行的方法
	    success: function(data){
	    	totalNumber = data;
    		$('#menzhensl').text(data);
	    	if(data==''){
				$(".wzl-jrmz-nav").addClass("wzl-jrmz-navadd");
			}
	    }
	});
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url:path+"/changguimz/getCount",
	    //传送数据
	    data:{zhuangtai:1,yewurk:1},//保存
	    async:false,
	    //请求成功完成后要执行的方法
	    success: function(data){
    		$('#zancunsl').text(data);
	    }
	});
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url:path+"/changguimz/getCount",
	    //传送数据
	    data:{zhuangtai:2,yewurk:1},//代收费
	    async:false,
	    //请求成功完成后要执行的方法
	    success: function(data){
    		$('#weishoufsl').text(data);
	    }
	});
	$.ajax({
	    type:"get",
	    //获取json文件路径
	    url:path+"/changguimz/getCount",
	    //传送数据
	    data:{zhuangtai:3,yewurk:1},//已收费
	    async:false,
	    //请求成功完成后要执行的方法
	    success: function(data){
    		$('#yishoufsl').text(data);
	    }
	});
	function createJinrimz(name) {
	var container = $('#pagination-'+name);
	container.pagination({
		dataSource:path+'/changguimz/getByPage?yewurk=3',
		locator: 'entities',
		pageSize: 5,
		totalNumber: totalNumber,
		callback: function(data, pagination) {
			$("#tbjinrmz").html('');
			var content = '';
				$.each(data, function (i, item) {
					var shoufeizt = '';
					if(this.zhuangtai == 1) {
						var shoufeizt = '保存';
					}else if(this.zhuangtai == 2) {
						var shoufeizt = '待收费';
					}else if(this.zhuangtai == 3) {
						var shoufeizt = '已收费';
					}
					if(this.yewurk == 1) {
						var yewurk = '微诊疗';
					}else if(this.yewurk == 3){
						var yewurk = '常规门诊';
					}

					content +='<tr id="'+this.id+'" leixing="1" yewurk="'+this.yewurk+'" class="zhuangt-row" >';
					content +=' <td width="20%">'+this.xiugaisj+'</td>';
					content +='<td width="40%" style="overflow:hidden;white-space: nowrap;text-overflow: ellipsis;">'+this.huanzhemc+'</td>';
					if(shoufeizt =='已收费'){
						content +='<td  width="20%" class=" cgmz-r1-ysf">'+shoufeizt+'</td>';
					}else if(shoufeizt == '待收费') {
						content +='<td  width="20%" class=" cgmz-r1-wsf">'+shoufeizt+'</td>';
					}else{
						content +='<td  width="20%">'+shoufeizt+'</td>';
					}
					content +='<td  width="20%">'+yewurk+'</td>';
					content +="</tr>";
				});
				$("#tbjinrmz").append(content);
				$(".wzl-jrmz-nav").removeClass("wzl-jrmz-navadd");
				
			
			
		}
	});
		return container;
	}
		createJinrimz('fenyjrmz');
		if(totalNumber <= 5) {
			$('#pagination-fenyjrmz').css('display','none');
		}
	};
	
	//药品名称输入事件
	$(document).on('input','.yaopinmc',function(){
		var parents = $(this).parents('.western-medicine');
		if($(this).val().length==13){
			isTxm = true;	
		}else{
			isTxm = false;
		}
		if($(parents).attr('class')!=undefined) {
			getYaopin(this,2);
		}else{
			getYaopin(this,1);
		}
	});
	//耗材费用点击一行
	$(document).on('input','.cgmz-l3-table1 .hzn-name-input2',function(){
		if($(this).val().length==13){
			isTxm = true;	
		}else{
			isTxm = false;
		}
		getHaocai(this);
	});
	//检查治疗项
	$(document).on('input','.cgmz-l3-table3 .hzn-name-input2',function(){
		$(this).removeClass('isChose');
		getJianchax(this);
	});
	/*主诉、病史等可以折行显示*/
	$("#div-allergy").on('input',function(){
		var tt = $("#div-allergy").text();
		if(tt.length > 200){
			var text =tt.substring(0,199);
			$(this).addClass("n-invalid");
			$(this).attr("contenteditable",false);
			$("#g-allergy").attr('readonly',true);
			$("#div-allergy").html(text);
			$(this).click(function(){
				$("#g-allergy").attr('readonly',false);
				$(this).attr("contenteditable",true);
			});
			notifyWarning("可输入最大长度为200个字符");
		}else if(tt.length<200){
			$(this).removeClass("n-invalid");
			$(this).attr("contenteditable",true);
			$("#g-allergy").attr('readonly',false);
			$("#g-allergy").val(tt);
			
		}
        
	});
	$("#div-zhushu").on('input',function(){
		var tt = $("#div-zhushu").text();
        if(tt.length>200){
			var text =tt.substring(0,199);
			$(this).addClass("n-invalid");
			$(this).attr("contenteditable",false);
			$("#first-info").attr('readonly',true);
			$("#div-zhushu").html(text);
			$(this).click(function(){
				$("#first-info").attr('readonly',false);
				$(this).attr("contenteditable",true);
			});
			notifyWarning("可输入最大长度为200个字符");
		}else if(tt.length<200){
			$(this).removeClass("n-invalid");
			$(this).attr("contenteditable",true);
			$("#first-info").attr('readonly',false);
			$("#first-info").val(tt);
		}
	});
	$("#div-disease").on('input',function(){
		var tt = $("#div-disease").text();
        if(tt.length>200){
			var text =tt.substring(0,199);
			$(this).addClass("n-invalid");
			$(this).attr("contenteditable",false);
			$("#input-disease").attr('readonly',true);
			$("#div-disease").html(text);
			$(this).click(function(){
				$("#input-disease").attr('readonly',false);
				$(this).attr("contenteditable",true);
			});
			notifyWarning("可输入最大长度为200个字符");
		}else if(tt.length<200){
			$(this).removeClass("n-invalid");
			$(this).attr("contenteditable",true);
			$("#input-disease").attr('readonly',false);
			$("#input-disease").val(tt);
		}
	});
	$("#div-history").on('input',function(){
		var tt = $("#div-history").text();
        if(tt.length>200){
			var text =tt.substring(0,199);
			$(this).addClass("n-invalid");
			$(this).attr("contenteditable",false);
			$("#input-history").attr('readonly',true);
			$("#div-history").html(text);
			$(this).click(function(){
				$("#input-history").attr('readonly',false);
				$(this).attr("contenteditable",true);
			});
			notifyWarning("可输入最大长度为200个字符");
		}else if(tt.length<200){
			$(this).removeClass("n-invalid");
			$(this).attr("contenteditable",true);
			$("#input-history").attr('readonly',false);
			$("#input-history").val(tt);
		}
	});
	
	$("#div-examine").on('input',function(){
		var tt = $("#div-examine").text();
        if(tt.length>200){
			var text =tt.substring(0,199);
			$(this).addClass("n-invalid");
			$(this).attr("contenteditable",false);
			$("#input-examine").attr('readonly',true);
			$("#div-examine").html(text);
			$(this).click(function(){
				$("#input-examine").attr('readonly',false);
				$(this).attr("contenteditable",true);
			});
			notifyWarning("可输入最大长度为200个字符");
		}else if(tt.length<200){
			$(this).removeClass("n-invalid");
			$(this).attr("contenteditable",true);
			$("#input-examine").attr('readonly',false);
			$("#input-examine").val(tt);
		}
	});
	$("#div-yizhu").on('input',function(){
		var tt = $("#div-yizhu").text();
        $("#cgmz-l3yz").val(tt);
        if(tt.length>200){
			var text = tt.substr(0,200);
			$("#div-yizhu").text(text);
			 $("#cgmz-l3yz").val(text);
			notifyWarning("可输入最大长度为200个字符");
		}
	});
	//回车转Tab
	//检查控件是否可见
	function checkobjvisual(e) {
	    var objvis = false;
	    if (e) {
	        if (e.offsetHeight > 0) {
	            objvis = true;
	        }
	        if (e.offsetTop > 0) {
	            objvis = true;
	        }
	         if (e.readOnly == true) {
	             objvis = false;  
	       }  
	    }
	    return objvis;
	}
	//查找下一个控件
	function focunext(next_id) {
	    var code;
	    if (!e) {
	        var e = window.event;
	    }
	    if (e.keyCode) {
	        code = e.keyCode;
	    }
	    else if (e.which) {
	        code = e.which;
	    }
	    if (code == 13) {


	        if (next_id)
	        {document.getElementById(next_id).focus(); }
	        else {
	            var inputList = document.getElementsByTagName("input");
	            // 循坏这个集合，包括了所有的input。
	            var nextindex;
	            nextindex = -1;
	            for (i = 0; i < inputList.length; i++) {
	                if (inputList[i] == document.activeElement) {
	                    var acobj = document.activeElement;
	                    nextindex = i + 1;
	                    
	                    while ((!checkobjvisual(inputList[nextindex])) && (nextindex <= inputList.length)) {
	                        nextindex = nextindex + 1;
	                    }
	                    if (inputList[nextindex])  inputList[nextindex].focus();
	                    break;
	                }
	            }
	            
	        }
	    }
	};
	document.onkeydown = function(e) {
		    var code;
		    if (!e) {
		        var e = window.event;
		    }
		    if (e.keyCode) {
		        code = e.keyCode;
		    }
		    else if (e.which) {
		        code = e.which;
		    }
		    if (code == 8) {
		        if (document.activeElement.readOnly == true || document.activeElement.disabled == true)
		        { return false; }
		    }
		    if (code == 13) {
		        if (document.activeElement.type == "textarea") {
		            return;
		        }
		        if (document.activeElement.type != "submit" && document.activeElement.type != "button") {
		 
		             event.keyCode = 9;
		             if(!enterToTab){
				    		enterToTab = true;
				    }else if(!isTxm){
				    	focunext();
				    }
		            isTxm = false;
		            return false;
		        }
		    }
		   
	}
	
//	//医保信息模块
//	function tianjiaybxx(yibaoxx){
//		var xinxi = yibaoxx.split("|");
//		var shengfenzh = xinxi[4];
//		var renyuanlb = xinxi[34];
//		var yibaokh = xinxi[9];
//		var bennianzhye = xinxi[15];
//		var linianzhye = xinxi[16];
//		$('#shengfenzh').val(shengfenzh);
//		$('#renyuanlb').val(renyuanlb);
//		$('#yibaokh').val(yibaokh);
//		$('#bennianzhye').val(bennianzhye);
//		$('#linianzhye').val(linianzhye);
//	}
function jisuanYmje() {
	var jine = 0.00;
	$('#formSave').find('[name="jine"]').each(function (){
		var Thisval = $(this).val();
	    var isHaoCai = $(this).parents().hasClass('tbhaocai');
	    var isCaoYao = $(this).parents().hasClass('chinese-medicine');
	    var isChengYao = $(this).parents().hasClass('western-medicine');
	    if (isHaoCai) {
	        var haocaisl  =  $(this).parent().parent().find('[name="shuliang"]').val();
	        jine = parseFloat(jine) + parseFloat(multiply(Thisval, haocaisl));
	    }
        if (isChengYao) {
            var chengyaosl  =  $(this).parent().parent().find('[name="kaiyaoliang"]').val();
            jine = parseFloat(jine) + parseFloat(multiply(Thisval, chengyaosl));
        }
        if (isCaoYao) {
            var tieshushuliang = $(this).parents('#chinese-medicine').find('#tieshu').val();
            var caoyaosl  =  $(this).parent().parent().find('[name="danjiliang"]').val();
            jine = parseFloat(jine) + parseFloat(multiply(multiply(Thisval, tieshushuliang), caoyaosl));
        }
        if (!isCaoYao && !isHaoCai && !isChengYao) {
            jine = parseFloat(jine) + parseFloat(getFloatStr(Thisval));
        }
	});
	jine=roundUtil(jine, 2);
	if($('#sphejije').text() != jine +'元'){
		if(jine){
			$('#sphejije').text(jine+'元');
		}else{
			$('#sphejije').text('0.00元');
		}
	}
}
//医保信息点击内容框不消失
$(document).on("mouseover", "#yibao-ybinfo", function() {
    $(this).addClass("hello");
});
$(document).on("mouseout", "#yibao-ybinfo", function() {
    $(this).removeClass("hello");
});
$(document).on("click", "#yibao-ybinfo", function() {
    if ($("#yibao-ybinfo").hasClass("hello")) {
        $(this).css("display", "block");
    } else {
        $(this).css("display", "none");
    }
    return false;
});
// 医保读卡类型控制
$('#yibao-ybinfo .dropdown-menu li').click(function(){
	var showTarget = $(this).parent().siblings('.dropdown-toggle').find('span');
	var myText = $(this).text();
	if (myText == "医保卡号") {
		showTarget.text("医保卡号").attr('chikalx', YBDUKALX_SHIMINKA);
		$(this).text("病历本号");
		$(this).parent().siblings('.yibaoinfo-type-input').attr('placeholder','请插入医保卡后点击读卡').attr('readOnly','readOnly');
		$(this).parent().parent().siblings('.yibaoinfo-head-text').attr('readOnly','readOnly').css('opacity','0');
		
	} else {
		showTarget.text("病历本号").attr('chikalx', YBDUKALX_ZHENGLIBEN);
		$(this).parent().siblings('.yibaoinfo-type-input').attr('placeholder','请输入病例本号').attr('readOnly',false);
		$(this).parent().parent().siblings('.yibaoinfo-head-text').attr('readOnly',false).css('opacity','1');
		$(this).text("医保卡号");
	}
	$(this).parent().toggle();
});
// 读卡按钮
$('#duka').click(function () {
	var leixing = $(this).siblings('.yibaoinfo-head-type').find('span').attr('chikalx');
	var chikalx;
	if (leixing == '1') {
		chikalx = '1';
	} else {
		chikalx = '0';
	}
	var count = 0;
	getYiBaojbrc(chikalx, count);
});
function getYiBaojbrc(chikalx, count) {
	$.ajax({
	    type: "POST",
	    url: path + "/yibao/getYbRenyuancbjbxx",
	    async: false,
	    data: {"chikalx": chikalx},
	    success: function(data) {
	    	var result = JSON.parse(data);
    		if (result.chenggongbz == YBMSG_YILIAOJGBHISNULL) {
    			notifyWarning('医疗机构编号未填写');
    			return false;
    		}	    	
	    	if (result.chenggongbz == MSG_FALI) {
	    		getDangqzedzcs();
	    		$('#yb-chongxinqd').val(data);
	    		$('#yb-chongxinqd').trigger('click');
	    		count++;
	    		if (count > 1) {
	    			notifyWarning('服务器忙碌,请稍后再试');
	    			return false;
	    		}
	    		getYiBaojbrc(chikalx,count);
	    	} else {
	    		var yewuzqh = $('#yb-yewuzqh').val();
	    		if (null != yewuzqh && yewuzqh !='') {
	    			updateYeWuzqh(yewuzqh);
	    		}	    		
	    		$('#yb_duka').val(data);
	    		$('#yb_duka').trigger('click');
	    		var huanzhexx = getHuanzhexxBygrbh(higerenbh);
	    		if (null != huanzhexx) {
	    			fillHuanzhexx(huanzhexx);
					// 患者折叠信息显示
					$('.zhedie').show();
					$('.huanz-message-down').hide();
	    		} else {
	    			$('#huanzhexx').trigger('click');
	    		}
	    	}
	    }
	});
}
// 填充患者信息
function fillHuanzhexx(huanzhexx) {
		huanzheid = huanzhexx.id;
		$('#inputname').val(huanzhexx.xingming);
		$('#inputname').attr('readOnly','true');
		if(huanzhexx.nianling != null) {
			$('#inputage').val(huanzhexx.nianling);
		}
		
		$('#inputphone').val(huanzhexx.shoujihm || '');
		$('#g-allergy').val(huanzhexx.guominshi);
		$('#div-allergy').html(huanzhexx.guominshi);
		
		if(huanzhexx.xingbie== 1) {
			$('#nan').attr('checked','checked');
			$('#work-label').attr('class','radio-label cgbj-input on');
			$('#stop-label').attr('class','radio-label');
		}else if(huanzhexx.xingbie==2){
			$('#nv').attr('checked','checked');
			$('#stop-label').attr('class','radio-label on');
			$('#work-label').attr('class','radio-label cgbj-input');
		}
		
		if(huanzhexx.nianlingdw=='岁') {
			$("#f-le-nianlingdw").text('岁');
		}else {
			$("#f-le-nianlingdw").text('月');
		}
		
		$('#isNew').val(0);
		$('#huanzheid').val(huanzhexx.id);
		$(".f-input-li").css("display","none");
		$('#hz_serch').val("");
		$(this).parent().html("");
		$(".xiangxiandls").css('display','block');
		$('.g-1lm-icon ').css("display","block");
		if (getLiShijzcs(huanzheid) != 0) {
			$('.g-l-1r-bottom').css('display','inline-block');
		} else {
			$('.g-l-1r-bottom').css('display','none');
		}
}
// 医保最近三天就诊明细查询
$(".f-bz").on("click",function(){
	if ($('#higerenbh').val() == '') {
		notifyWarning("请先进行读卡!");
		return false;
	}
	$(this).addClass("on").siblings().removeClass("on");
	$('#yb-jiuzhenxxmx').val($(this).text());
	var YibaoParams = getYiBaorc();
	$('#yb-YiBaoParams').val(YibaoParams);
	$('#yb-jiuzhenxxmx').trigger('click');
});